Hi there,
I have made a Server-Script, which is supposed to work for every single player at the same time (at least I am trying to do so). It’s supposed to connect something, after a child has been added inside a folder (the childs name is: object) and then connect a second event, which is triggered after the player clicked the object. Later there’s a Remote-Event inside the second connection.
So like this actually:
Folder.ChildAdded:Connect(function(Object)
...
Object.InteractingClickDetector.MouseClick:Connect(function(Player) -- !!! This is causing the problem
...
for i,v in pairs(Players:GetPlayers()) do
v.Character.PlayerRemoteEvents.PressingGuiButton.OnServerEvent:Connect(function(...)
...
end)
end
end)
end)
Now my problem is, every time the player clicks the object, the connection (which is marked with the “!!!”) keeps stacking more and more, depending on how often any of the objects are clicked. If the objects gets clicked twice, the event inside the connection with the Mouse-Click happens twice and if it gets clicked 3 times, it also happens 3 times.
I could fix that with a :disconnect() command, but it’s very complicated to implement that into my script. That’s because the Remote-Event, which can get triggered after the Mouse-Click, has something inside of it, that handles the players actions like adding something to a value, until it has reached a specific amount. I can’t disconnect that because then the player won’t be able to do his task anymore. I could only use :disconnect() after the player is finished, but that won’t fix the problem, that 2 players are using the event at the sime time and manipulating each other. Both players would get the doubled amount, because there are 2 connections.
I am really confused about my problem, because there seems to be no solution for this. (At least not for me, but maybe there’s somebody out here, that has an idea about how to fix this.)
Are there any ways, to make the connections not affect each other? (Like creating seperate scripts or something)? I guess I could also remake my whole entire Server-Script, but I think that will be much more work than trying finding a solution.
I am not going to show the entire script, because it’s not necessary here. The problem is only caused by the few lines of script, which I showed above. But I could still send the part of the Remote-Event if you need to take a look at it.
Thanks to anyone who tries to help me in this situation.
Also:
I should mention that there are 4 objects (let’s say workstations instead), which should handle one player each. So my script must be able to handle 4 connections, which can’t be able to manipulate each other. It works perfectly fine if there’s only 1 player using one of the 4 workstations. But if a second player comes and clicks a diffrent workstation, the connections (like I said) stack into each other.