Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.