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

Why is my Debounce not preventing my script from firing multiple times?

Asked by
PastDays 108
6 years ago

Every time i attempt debouce it doesn't work, what is it i'm doing wrong?

01function onTouched(hit)
02    local debounce = true
03    if debounce == true then
04        debounce = false
05    game.ServerStorage.GameFiles.Storage.Area1:Clone().Parent = game.Workspace.GameFiles.MapStorage
06    local part = game.Workspace.GameFiles.MapStorage.Area1.Location.Position
07    wait(2)
08    hit.Parent:moveTo(part)
09    game.Workspace.GameFiles.MapStorage.SpawnMap:Destroy()
10    end
11    wait(10)
12    debounce = true
13end
14 
15connection = script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
1
Answered by
Troxure 87
6 years ago

You need to put 'local Debounce = true' above the function, not in it.

01local debounce=true
02 
03function onTouched(hit)
04if debounce == true then
05debounce = false
06game.ServerStorage.GameFiles.Storage.Area1:Clone().Parent = game.Workspace.GameFiles.MapStorage
07local part = game.Workspace.GameFiles.MapStorage.Area1.Location.Position
08wait(2)
09hit.Parent:moveTo(part)
10game.Workspace.GameFiles.MapStorage.SpawnMap:Destroy()
11end
12wait(10)
13debounce = true
14end
15connection = script.Parent.Touched:connect(onTouched)
0
I'll save this and use it as a template, Thank you! PastDays 108 — 6y
0
Youre welcome Troxure 87 — 6y
Ad

Answer this question