local function t(t)local K=(t.Size.X*t.Size.Y)*t.Size.Z local s=(_DENSITY*_VOLUME)/K t.CustomPhysicalProperties=PhysicalProperties.new(s,.3,.5)end local function K(t,K,s)local o=workspace:FindFirstChild("\082\097\099\101\116\114\097\099\107")local a=workspace:FindFirstChild("\069\110\118\105\114\111\110\109\101\110\116 \065\115\115\101\116\115")local j=a:FindFirstChild("\080\108\097\110\116\115")if not t:IsDescendantOf(s.speeder)and(not t:IsDescendantOf(o)and(not t:IsDescendantOf(j)and not(t==workspace.SpeederSpawnLocation)))then local t=Explosion:Clone()t.CFrame=K.CFrame t.Parent=workspace character:Destroy()ExplosionSound:Play()local s=PlayerGui:FindFirstChild("\068\101\115\107\116\111\112\071\117\105")or PlayerGui:FindFirstChild("\067\111\110\115\111\108\101\071\117\105")or PlayerGui:FindFirstChild("\077\111\098\105\108\101\071\117\105")if s then s.Enabled=false end local o=t:GetChildren()for t,K in pairs(o)do if K:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then K:Emit(10)end end spawn(function()wait(PARTICLE_DURATION)t:Destroy()end)spawn(function()wait(2)PlayerConverter:SpeederToPlayer(false)end)end end local function s(t,o)for t,a in pairs(t:GetChildren())do if(a:IsA("\066\097\115\101\080\097\114\116")or a:IsA("\077\101\115\104\080\097\114\116"))and(a.Name~="\072\101\097\100"and(a.Name~="\085\112\112\101\114\084\111\114\115\111"and a.Name~="\065\114\114\111\119"))then a.Touched:Connect(function(t)K(t,a,o)end)s(a,o)end end end

local function SetMass(part)
	local volume = part.Size.X * part.Size.Y * part.Size.Z
	local newDensity = _DENSITY * _VOLUME / volume
	
	-- Defaults except newDensity (density, friction, elasticity)
	part.CustomPhysicalProperties = PhysicalProperties.new(newDensity, 0.3, 0.5)
end -- SetMass()

local function HandleCollision(collidedPart, part, self)
	local RaceTrack = workspace:FindFirstChild("Racetrack")
	local EnvironmentAssets = workspace:FindFirstChild("Environment Assets")
	local Plants = EnvironmentAssets:FindFirstChild("Plants")
	
	if not collidedPart:IsDescendantOf(self.speeder) and not collidedPart:IsDescendantOf(RaceTrack)
	 and not collidedPart:IsDescendantOf(Plants) and not (collidedPart == workspace.SpeederSpawnLocation) then	
		-- Create particle effect
		local particle = Explosion:Clone()
		particle.CFrame = part.CFrame
		particle.Parent = workspace

		character:Destroy()
		ExplosionSound:Play()
		
		local planeGui = PlayerGui:FindFirstChild("DesktopGui") or 
			PlayerGui:FindFirstChild("ConsoleGui") or
			PlayerGui:FindFirstChild("MobileGui")
		if planeGui then
			planeGui.Enabled = false
		end
	
		local emitterChildren = particle:GetChildren()
	
		for _, child in pairs(emitterChildren) do 
			-- If the child is a particle, then cause it to emit
			if child:IsA("ParticleEmitter") then
				child:Emit(10) 
			end
		end

		-- Destroy particle after PARTICLE_DURATION seconds
		spawn(function() 
			wait(PARTICLE_DURATION) 
			particle:Destroy() 
		end)
		-- Convert speeder to player
		spawn(function() 
			wait(2)
			PlayerConverter:SpeederToPlayer(false)
		end)	
	end
end -- handleCollisions()

local function SetupCollisionDetection(parent, self)
	for _,part in pairs(parent:GetChildren()) do
		if (part:IsA("BasePart") or part:IsA("MeshPart")) and part.Name ~= "Head" and 
			part.Name ~= "UpperTorso" and part.Name ~= "Arrow" then
			part.Touched:Connect(function(collidedPart) HandleCollision(collidedPart, part, self) end)
			SetupCollisionDetection(part, self)
		end
	end
end -- setupCollisionDetection()