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

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

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

✓ Accepted answer

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)

2 comments

0

I'll save this and use it as a template, Thank you!

0

Youre welcome

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