What do i want to achieve? I want to give a tool to the player when he trigger a proximityprompt, but in the server side so i fireserver
What is the issue? The first time it works perfectly, but the second time the tools start duplicating (for example the second time it gives the player 2 tools, the third time it gives the player 4 tools…)
this is the script
--CLIENT
game.Workspace.Canada.cookingtable.pan.prox2.Triggered:Connect(function()
clonedtextlabel:Destroy()--just a label in a bilboardGUI
game.Workspace.Canada.cookingtable.rawsyrup.Transparency = 1
game.Workspace.Canada.cookingtable.pan.prox2.Enabled = false --disbale the prox
wait(1) -- i tried to add a lot of wait(), but it didn't solve my problem :(
game.ReplicatedStorage.maplesyrupinthebackpack:FireServer(game.Players.LocalPlayer)
Basically i do all the things on the client side (for example i enabled it on the client side). There is a long script before this all on the client side
Yeah so every time something gets added to the backpack it makes a new event which is basically the same event. So when you trigger the proximity it actually fires 2 events.
You would need to disconnect them manually since they do not disconnect automatically except if the instance where the event is connected gets destroyed.
local isFired = false
blablahblah.Triggered:Connect(function(player)
if isFired then return end
eventFired = true
--// ur code
task.wait(5)
eventFired = false
I wrote an example for you of how you can use this in your case. To not make a new connection everytime.
local connections = {}
if not connections['Syrup'] then -- Make sure to not use the same name for every connection you want here.
connections['Syrup'] = prompt.Triggered:Connect(function()
-- Do whatever you want here
end)
end
It is not working, but maybe i am putting it in the wrong place…
local connections = {}
if not connections['Syrup'] then
connections['Syrup'] = game.Workspace.Canada.cookingtable.pan.prox2.Triggered:Connect(function()
clonedtextlabel:Destroy()--just a label in a bilboardGUI
game.Workspace.Canada.cookingtable.rawsyrup.Transparency = 1
game.Workspace.Canada.cookingtable.pan.prox2.Enabled = false --disbale the prox
wait(1) -- i tried to add a lot of wait(), but it didn't solve my problem :(
game.ReplicatedStorage.maplesyrupinthebackpack:FireServer(game.Players.LocalPlayer)