How does debounce work?

Well if we put a debounce shoukdn’t it overwrite how does it make it sure that the debounce is for each player and the values dont overwrite for example, player A has a wait time of 5 seconds but player b steps in and the debiunce gets reset why doesn’t this happen, I been scripting for a long time and I dont get basic stuff like this lol

Have you read the documentation about debounce?

Ok,that doesn’t really answer the question the roblox page. I know what debounce does, but how is it different for each client?

If you’re doing it on a local script it will be separate and debounces won’t overlap. However since there isn’t more than one server, you need to account for each player’s debounce in a server script, you can manage this with a table.

Then why does the debounce work in a serverscript?

A debounce works equally on any code, the difference is what side is running it. There’s a client for each player but one server for all clients.

1 Like

When Im running it on a server each client gets there own debounce.

I’m not sure what you’re saying or mean. It depends on what you’re doing on the server.

For example even if I do a simpe deboune script, like a laser script

If you’re running on the server a debounce won’t work for all players. Like @ArtFoundation suggested. A table that holds all the player’s objects would do the trick, and checking if the bool is false in that player’s index, if so then set the bool to true.

Hmm, im really confused why it worked for me can I PM you tommrow its pretty late about any questions I have?

If it worked for you, your test is probably not a valid test. Sure it’ll work for a single player but probably won’t work for a server filled with people.

If you mean a script inside a tool then it’s because each tool has their own script and is replicated when the game starts for each individual player. So if you have server scripts that are for each individual person, the debounce works because it’s for only one person at a time and the script is being given to one individual player at a time.

2 Likes

A debounce is a mechanism meant to prevent certain actions from occurring within a given interval of time: for example, a cooldown system for a sword where you can’t swing for at least 3 seconds after your last swing. This can be answered from the Developer Hub article, search before posting.

Your question otherwise is unclear, not sure what you’re asking. Debounces are a form of rate limiting (?), not overwriting or whatever. This sounds like an implementation error, so please show some actual code and perhaps explain what’s wrong with the code so we can better help you.

2 Likes

I think what ArtFOundation said was right, and what I said is not in the link so please read my question. Anways thanks.

I read your question but it was frankly very confusing, hence the second paragraph. I answered based on the title, “How does debounce work”. If your question was something else, it would be better to clarify that in the thread and the title as well.

If you were just looking for individual debounces, then the article is still applicable for the code in whatever system you’re working with. Debounces and other script systems are never global unless you make it that way: for example, if you don’t track individual players’ debounces for a RemoteEvent in a script handling the server-side for a system (remotes).

1 Like

Well, I told you my question was answered I don’t need you to answer my question again. Oh yah sorry, I forgot to put the solution that was my fault.

Threads are public resources. The OP isn’t the only one who reads threads, this information can be helpful for other developers as well who are reading through.

A reply isn’t null if it’s related to the thread and provides useful insight on the matter, even if it’s different to the marked solution. Never know when it may potentially give more information. Solutions don’t necessarily mean that a thread is closed, just that you found the best answer.

:slight_smile:

3 Likes

Debounces are a concept and implementation, not a datatype so it has no set behavior. What Art said definitely is true; and if only one player is writing and reading the variable you wont encounter an issue. (Unless you use a global variable).

And @colbert2677 gave a spot on definition on what the debounce implementation is. But its important to note that debounces can handle multiple players as well. This can be done with a hash mapping player to bool. It really depends on the debounce variable locality, datatype, and whats reading/writing to it.
But It seems like this thread is answering the notion that variables aren’t shared between scripts (thus variables are only local to their respective scripts), rather than how debounces work.

1 Like