RemoteEvent Firing multiple times

Hello. This is my first article on the DevForum as I could not find a solution to my problem. Basically, the issue is that I have a button that will give a tool to a player, in a menu with 3 tools to choose from, but the remote event fires multiple times. It doesn’t matter in which order you take the tools, but the first one fires the event once, the 2nd one fires 3, 3rd one fires times 6, and keeps going up in increments of 3.

client-side:

script.Parent.Menu.Option1.MouseButton1Click:Connect(function()
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			game.ReplicatedStorage.WorkerEvent:FireServer("Option1")
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			script.Parent.ClosingAlt.Position = UDim2.new(0.017, 0,0.128, 0)
			script.Parent.Menu.Position = UDim2.new(-4,-4,-4,-4)
		end)

serverside:

game.ReplicatedStorage.WorkerEvent.OnServerEvent:Connect(function(player, value1)
	if value1 == "Option1" then
		local clone = game.ReplicatedStorage["ham sandwich"]:Clone()
		clone.Parent = player.Backpack
		print("given")
	end
end)

Thank you to anybody who helps me with this.

1 Like

Is this the entire script? I don’t see anything that would cause it to increase in multiples of three.

You might wanna use MouseButton1Down. That could possibly fix your issue.

this is only a small portion of the script.
(it was working fine earlier but i went into studio to publish it and it started acting odd.)

Shouldn’t really make a difference.

So given first prints once, then three times, and then six times?

Pretty sure using Click instead of Down will trigger until the left click is fully pressed.

I just tried changing MouseButton1Click to MouseButton1Down and it did not make a difference.

Click triggers only when the left button is released after being clicked, I’ve used it many times and haven’t had any issues with using click so I doubt it’s that. It’s most likely something else in the script not in the snippet.

Also yes, it prints once, then 3 times, then 6, then 9, and so on.

1 Like

Would it be helpful if i sent the entire script?

1 Like

Do Find (Which is up in the top bar) and search

WorkerEvent:FireServer

this is the client script:

local workerman = game.Workspace.workerman
local camera = workspace.CurrentCamera
local opensidemenu = script.Parent.Parent.Menu.OpenSideMenu

workerman.Torso.ActivateDialogue.Triggered:Connect(function()
	
	camera.CameraType = Enum.CameraType.Scriptable
	camera.FieldOfView = 50
	opensidemenu.Visible = false
	
	camera.CFrame = game.Workspace:WaitForChild("CameraPart2").CFrame
	
	script.Parent.Opening.Position = UDim2.new(0.017, 0,0.128, 0)
	workerman.Torso.ActivateDialogue.Enabled = false
	
	script.Parent.Opening.TextButton.MouseButton1Down:Connect(function()
		script.Parent.Opening.Position = UDim2.new(-4,-4,-4,-4)
		script.Parent.Menu.Position = UDim2.new(0.017, 0,0.128, 0)
		script.Parent.Parent.Menu.Sidebar.Confirm:Play()
		
		script.Parent.Menu.Option1.MouseButton1Down:Connect(function()
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			game.ReplicatedStorage.WorkerEvent:FireServer("Option1")
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			script.Parent.ClosingAlt.Position = UDim2.new(0.017, 0,0.128, 0)
			script.Parent.Menu.Position = UDim2.new(-4,-4,-4,-4)
		end)
		
		script.Parent.Menu.Option2.MouseButton1Down:Connect(function()
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			game.ReplicatedStorage.WorkerEvent:FireServer("Option2")
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			script.Parent.ClosingAlt.Position = UDim2.new(0.017, 0,0.128, 0)
			script.Parent.Menu.Position = UDim2.new(-4,-4,-4,-4)
		end)
		
		script.Parent.Menu.Option3.MouseButton1Down:Connect(function()
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			game.ReplicatedStorage.WorkerEvent:FireServer("Option3")
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			script.Parent.ClosingAlt.Position = UDim2.new(0.017, 0,0.128, 0)
			script.Parent.Menu.Position = UDim2.new(-4,-4,-4,-4)
		end)	
		
		script.Parent.Menu.Exit.MouseButton1Click:Connect(function()
			script.Parent.Menu.Position = UDim2.new(-4,-4,-4,-4)
			script.Parent.Closing.Position = UDim2.new(0.017, 0,0.128, 0)
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
		end)
		
		script.Parent.Closing.TextButton.MouseButton1Click:Connect(function()
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			camera.FieldOfView = 75
			camera.CameraType = Enum.CameraType.Custom
			opensidemenu.Visible = true
			game.Workspace.workerman.Torso.ActivateDialogue.Enabled = true
			script.Parent.Closing.Position = UDim2.new(-4,-4,-4,-4)
		end)
		
		script.Parent.ClosingAlt.TextButton.MouseButton1Click:Connect(function()
			script.Parent.Parent.Menu.Sidebar.Confirm:Play()
			camera.FieldOfView = 75
			camera.CameraType = Enum.CameraType.Custom
			opensidemenu.Visible = true
			game.Workspace.workerman.Torso.ActivateDialogue.Enabled = true
			script.Parent.ClosingAlt.Position = UDim2.new(-4,-4,-4,-4)
		end)
	end)
end)

here is server side:

game.ReplicatedStorage.WorkerEvent.OnServerEvent:Connect(function(player, value1)
	if value1 == "Option1" then
		local clone = game.ReplicatedStorage["ham sandwich"]:Clone()
		clone.Parent = player.Backpack
		print("given")
		
	elseif value1 == "Option2" then
		local clone = game.ReplicatedStorage["turkey sandwich"]:Clone()
		clone.Parent = player.Backpack
		print("given")
		
	elseif value1 == "Option3" then
		local clone = game.ReplicatedStorage["grilled cheese"]:Clone()
		clone.Parent = player.Backpack
		print("given")
	end
end)

Why are they all nested in a function call that only runs when clicked?

Make sure you have no repeat loops / while / for loops going threw the same event, or even check if another script is using the same event.

1 Like

I agree that it may be wise to rewrite the client side script to be more organized but i dont belive that to be the issue as this was working earlier but it stopped after i closed and reoped studio later in the day.

On second thought, it will probably be best if I rewrite and organize the client-side script. I wont have time to do it today but thats probably the sollution.

I reorganized the scripts to make them neater and it fixed the problem. Still unsure what was causing the issue in the first place…

1 Like

I believe it might’ve been because you probably had a function in the thread of the RemoteEvent.OnserverEvent

That’s what caused mine to run multiple times