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

Script goes crazy, how to put a cooldown on it?

Asked by 6 years ago

Hello, I've got this kind of simple script here, it works like this:

You touch a part, and then a model moves.

The problem is, if you keep touching the part, which isn't supposed to happen, the script goes nuts and moves way too fast.

How do I fix this?

Script:

01workspace.BlockingGate.PrimaryPart = workspace.BlockingGate.Center
02 
03script.Parent.Touched:connect(function()
04    for i = 1,100 do
05        wait()
06 
07        workspace.BlockingGate:SetPrimaryPartCFrame( CFrame.new(workspace.BlockingGate.PrimaryPart.Position + Vector3.new(0,-0.5,0)) )
08 
09    end
10 
11    wait (2)
12 
13 
14 
15for i = 1,100 do
View all 24 lines...

Thanks for helping

1 answer

Log in to vote
0
Answered by
Oficcer_F 207 Moderation Voter
6 years ago

You need to add a debounce:

01debounce = false
02workspace.BlockingGate.PrimaryPart = workspace.BlockingGate.Center
03script.Parent.Touched:connect(function()
04if debounce == false then
05debounce = true
06    for i = 1,100 do
07        wait()
08 
09        workspace.BlockingGate:SetPrimaryPartCFrame( CFrame.new(workspace.BlockingGate.PrimaryPart.Position + Vector3.new(0,-0.5,0)) )
10 
11    end
12 
13    wait (2)
14 
15 
View all 28 lines...

This should work!

Ad

Answer this question