Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When I add a wait to my function it doesn't work? and how can I fix it?

Asked by 5 years ago

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)
0
use an if statement with a debounce and use wait() with that debounce greatneil80 2647 — 5y
0
On line 15 it should be 'while wait() do' Impacthills 223 — 5y

Answer this question