Promblem

Hey! I made a script where whenever the player touches a part in the workspace it sets a loop of parts the go behind the players legs. I wanted to add a wait to it but it doesn't work. Why and how can i fix this?

Local Script

local Player = game.Players.LocalPlayer
local char = Player.Character
local root = char.HumanoidRootPart 
walking = false


Player.Character.Humanoid.Running:connect(function(speed)
	workspace.Sand.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
    if speed == 0 then
	walking = false
       	game.ReplicatedStorage.RemoteEvent:FireServer(char,root)
    elseif speed > 0 then
	walking = true
        while wait do
	wait(2)
	if not walking then return end
end
    end
end
	end)
end)


workspace.Sand.TouchEnded:Connect(function()
	walking = false
end)

Server Script


game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player,char,root)
	local Part = Instance.new("Part")
	Part.Parent = workspace
	Part.Anchored = true
	Part.CanCollide = false
	Part.CFrame = root.CFrame * CFrame.new(0,-2,3)
end)

2 comments

0

use an if statement with a debounce and use wait() with that debounce

0

On line 15 it should be 'while wait() do'