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

after the wait() code line my script won't work, why?

Asked by 2 years ago

So, I have this script:

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if hit and hit.Parent:FindFirstChild("Humanoid") then
        humanoid.WalkSpeed = 0
        hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = workspace.CamerasCutscene1.Cam2.CFrame + Vector3.new(0, 0, 0)
        wait(2)
        humanoid.WalkSpeed = 9
    end
end)

and because of the wait(), the script won't work, if I delete it it works. But I really need that wait() to be there, can anyone tell me why, is this happening?

Thanks For Reading!

1 answer

Log in to vote
0
Answered by 2 years ago

Your solution is actually a pretty common one. You need to add a Debounce to your script. The .Touched event gets called pretty quick multiple times. Adding a Debounce will get what you want. Here's an article to help you. Article.

Ad

Answer this question