When i try to give a tool to a player via fireserver it duplicates after the second time

  1. 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

  2. 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)

--SERVER

game.ReplicatedStorage.maplesyrupinthebackpack.OnServerEvent:Connect(function(plr)
	
	local toolclonedmaplesyrup = game.ReplicatedStorage.Maple_syrup:Clone()
	wait()
	toolclonedmaplesyrup.Parent = plr.Backpack
	
end)	

most likely it will be a very trivial mistake, but in some cases I just can’t think and find a solution (like in this one). I’m sorry guys for this

1 Like

Why don’t you just put the proximity prompt on the server?

3 Likes

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

1 Like

Show the script above as well, you probably make multiple connections.

2 Likes

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.

Uh thx. I get it… How can i solve this problem? Maybe i have to end) the function before?

You would need to disconnect them manually since they do not disconnect automatically except if the instance where the event is connected gets destroyed.

1 Like

How fast holding time do you have on the ProximityPrompt?

1 Like

image

How many times do you fire it?

1 Like

I would put all the connections in a table and check if the connection is already made. If it’s made do not make a new connection.

1 Like

ehm… i don’t get what do you mean. Can you explain exatly what do i have to do pls? (sry i’m still beginner XD)

i have no idea to how to make it sry…

can’t you put at the top like:

local isFired = false



blablahblah.Triggered:Connect(function(player)
if isFired then return end

eventFired = true

--// ur code

task.wait(5)
eventFired = false

end)

idk try this

1 Like

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

1 Like

nvm, this example is better than mine. :smiley:

1 Like

This works but it would not prevent it from creating a new connection every time a tool is added. It’s just a longer debounce.

2 Likes

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)

should i use
table.insert
for add the connection?

@Proscled

1 Like

Put the table on top of the script now you’re creating a new table every time a new tool gets added.

2 Likes

Thank you so much. It is working

1 Like