local G=.4 local E=3.1 local x=game.Players.LocalPlayer game.ReplicatedStorage.Interactions.Client.Perks.ShowFootsteps.OnClientEvent:connect(function(S)if x.Character~=nil then local w=x.PlayerScripts.Functions.GetRayIgnoreList:Invoke()for S,s in pairs(S)do local k=s.Character if k:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")and s~=x then local S=false local s=G local D=Color3.fromHSV(math.random(),1,1)spawn(function()while wait(s)do if k.Parent==nil or k:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")==nil then break end local q=Ray.new(k.HumanoidRootPart.Position,Vector3.new(0,-E,0))local p,N=workspace:FindPartOnRayWithIgnoreList(q,w,false,true)if p~=nil and k.HumanoidRootPart.Velocity.Magnitude>1 then local E if S then E=k.HumanoidRootPart.CFrame*CFrame.new(-0.5,-2.95,0)S=false else E=k.HumanoidRootPart.CFrame*CFrame.new(.5,-2.95,0)S=true end x.PlayerScripts.Functions.PlaceFootstep:Fire(E,D,k.Humanoid)s=G else s=.033 end end end)end end end end)

local FOOTSTEP_PLACEMENT_RATE = 0.4
local GROUND_DETECTION_DISTANCE = 3.1

local plr = game.Players.LocalPlayer

game.ReplicatedStorage.Interactions.Client.Perks.ShowFootsteps.OnClientEvent:connect(function(plrs)
	
	-- Make sure character is alive
	if plr.Character ~= nil then
	
		-- Set up detection part for each player
		local ignore = plr.PlayerScripts.Functions.GetRayIgnoreList:Invoke()
		for _, i in pairs(plrs) do
			local thisChr = i.Character
			if thisChr:FindFirstChild("HumanoidRootPart") and i ~= plr then
				local left = false
				local waitTime = FOOTSTEP_PLACEMENT_RATE
				local color = Color3.fromHSV(math.random(), 1, 1)
				spawn(function()
					while wait(waitTime) do
						
						-- Check if detection part is gone or owner is gone
						if thisChr.Parent == nil or thisChr:FindFirstChild("HumanoidRootPart") == nil then
							break
						end
						
						-- Check if should place a foot step
						local ray = Ray.new(thisChr.HumanoidRootPart.Position, Vector3.new(0, -GROUND_DETECTION_DISTANCE, 0))
						local hit, hitPos = workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)
						if hit ~= nil and thisChr.HumanoidRootPart.Velocity.Magnitude > 1 then
							
							-- Tell the owner to place a footstep
							local cfr
							if left then
								cfr = thisChr.HumanoidRootPart.CFrame * CFrame.new(-0.5, -2.95, 0)
								left = false
							else
								cfr = thisChr.HumanoidRootPart.CFrame * CFrame.new(0.5, -2.95, 0)
								left = true
							end
							plr.PlayerScripts.Functions.PlaceFootstep:Fire(cfr, color, thisChr.Humanoid)
							
							-- Set wait time to be the placement rate
							waitTime = FOOTSTEP_PLACEMENT_RATE
						
						else
							
							-- Set wait time to be quick
							waitTime = 0.033
							
						end
						
					end
				end)
			end
		end
		
	end
	
end)
