local function q(q)local r=(q.Size.X*q.Size.Y)*q.Size.Z local w=(_DENSITY*_VOLUME)/r q.CustomPhysicalProperties=PhysicalProperties.new(w,.3,.5)end local function r(q,r,w)local B=workspace:FindFirstChild("\082\097\099\101\116\114\097\099\107")local E=workspace:FindFirstChild("\069\110\118\105\114\111\110\109\101\110\116 \065\115\115\101\116\115")local v=E:FindFirstChild("\080\108\097\110\116\115")if not q:IsDescendantOf(w.speeder)and(not q:IsDescendantOf(B)and(not q:IsDescendantOf(v)and not(q==workspace.SpeederSpawnLocation)))then local q=Explosion:Clone()q.CFrame=r.CFrame q.Parent=workspace character:Destroy()ExplosionSound:Play()local w=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 w then w.Enabled=false end local B=q:GetChildren()for q,r in pairs(B)do if r:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then r:Emit(10)end end spawn(function()wait(PARTICLE_DURATION)q:Destroy()end)spawn(function()wait(2)PlayerConverter:SpeederToPlayer(false)end)end end local function w(q,B)for q,E in pairs(q:GetChildren())do if(E:IsA("\066\097\115\101\080\097\114\116")or E:IsA("\077\101\115\104\080\097\114\116"))and(E.Name~="\072\101\097\100"and(E.Name~="\085\112\112\101\114\084\111\114\115\111"and E.Name~="\065\114\114\111\119"))then E.Touched:Connect(function(q)r(q,E,B)end)w(E,B)end end end
-- Sets the mass of the specified part by adjusting its density so that all
-- speeders will have the same mass (using static _DENSITY and _VOLUME)
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()
