How would I make a client mouse hold down FireServer for this

So I have a building system that depends on holding down the left mouse button but the problem is you can only detect mouse left button holding on the client side this isn’t a good thing for my script because I’m using a visual Part in workspace to show how much longer left you have to hold the mouse button down so to make the transition smooth of the visual scaling Part I will have to FireServer each time a number is changed in the progress bar which is a variable which will also probably changed each 0.01 seconds and check if the player let go of their mouse left buttons this will create performance problems as I heard I also should note I’m am Using FireServer because I want every player in the game to see the building progress bar go up So my question is how would you do this for better performance
If Your confused of what I am talking about say your confused and I will rephrase this topic

You could simply just Fire your remote once the player holds down their mouse and then fire to the server again when its released. This would save you the trouble of having to constantly check from the client.

2 Likes

I understand what you are saying but how would I stop the first FireServer event which will be a while wait() do with a second FireServer event know the fact multiple people will be using this FireServer event

I believe you have a misunderstanding about how Remote Events work. Each event is its own “thread”. Therefore two (or more) people can call the same remote at once. Let me provide an example.

Say you have a remote event which binds to the following:

Remote.OnServerEvent:Connect(function()
     wait(5)
     print("Hello world")
end)

Now, Player 1 activates the remote. Player 2 activates the remote at the same time. What do you think will happen? With your way of thinking, you might think that it will wait 5 seconds, do the print for Player 1’s remote, then wait another 5 seconds, and do the print for Player 2’s remote. The correct answer is that it will print both Hello Worlds at the same time. This is because each call to the remote event is separate from the other calls, and doesn’t rely on each other. It is similar to the topic of “coroutines” where each remote is kind of like its own thread.

Therefore, you can have a for/while loop inside of the remote event code, and it won’t hold up other remote events. It will run the loops at the same time. In our example, both remotes were doing the wait(5) at the same time when being called, and then printed the hello world at the same time.

1 Like

I thought of the same thing and thought of a solution which there is a probably a more cleaner way to make the script more organized but this is the way I thought of
Using dictionary to solve this problem
Once the player left click hold starts on the client side it FireServer() and checks if the player is in a dictionary if it isn’t it creates the player as a variable in the dictionary and sets it as false and now a while wait() do begins and checks if the player dictionary == true then break
Now once the player lets go their mouse another FireServer begins and this one will check if the player is in the dictionary and if they are then set their dictionary as true

Do yall have any thoughts to make this more clean

Yes thats the best thing to do for server side debounce.

1 Like

I will try to do this once I get home on the mean time if anyone has any ideas to do this any better please let me know