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

Can i use the same debounce variable more than once?

I don't have a script for what i mean, but i was just hoping to get clarification. Let's say I have a debounce variable called "ready", and I use it so that a player can't spam a key more than once every 5 seconds. Would it work to use that same variable in another part of your code, or would it mess the entire script up?

2 comments

0

Depends if ready is in the scope of the other part of your code. If ready is not contained within your function and is say at the top of your code, then yes it will be effected by continuing to use it with another part of your script.

0

Yes it's possible.

1 answer

✓ Accepted answer

Depends on the conditions. If your ready is like;

local ready = false

--Your fire event

then you other part of the script may intercept.

if your code is more like this;

script.Parent.MouseButton1Down:Connect(function()
	local ready = false
end)

then you can not use ready again because it will create a variable called ready when the button is clicked.

In the end I suggest you create 2 ready variables, maybe ready1 and ready2 but otherwise it may intercept with the other part of the script.

If you mean by 2 different scripts then you need to create a new variable.

If this helped then please accept answer ;)

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