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?

function onTouched(hit)
    local debounce = true
    if debounce == true then
        debounce = false
    game.ServerStorage.GameFiles.Storage.Area1:Clone().Parent = game.Workspace.GameFiles.MapStorage
    local part = game.Workspace.GameFiles.MapStorage.Area1.Location.Position
    wait(2)
    hit.Parent:moveTo(part)
    game.Workspace.GameFiles.MapStorage.SpawnMap:Destroy()
    end
    wait(10)
    debounce = true
end

connection = 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.

local debounce=true

function onTouched(hit)
if debounce == true then
debounce = false
game.ServerStorage.GameFiles.Storage.Area1:Clone().Parent = game.Workspace.GameFiles.MapStorage
local part = game.Workspace.GameFiles.MapStorage.Area1.Location.Position
wait(2)
hit.Parent:moveTo(part)
game.Workspace.GameFiles.MapStorage.SpawnMap:Destroy()
end
wait(10)
debounce = true
end
connection = 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