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:

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

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