RemoteEvent fires multiple times depends on amount of players in-game

Hello, I’ve been having issues with remote events firing multiple times depends on the amount of players that are in-game.

I’ve used a local script to receive the call from server side and send it to the server
Server → Client → Server

Here’s the example script from each side:

This is the script from the server side sending a signal to the client.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local MainEvents = ReplicatedStorage:WaitForChild("MainEvents")
local InGameEvents = MainEvents:WaitForChild("InGameEvents")
local LaserEnablation = InGameEvents:WaitForChild("LaserEnablation")
local ProtectorEnblation = InGameEvents:WaitForChild("ProtectorEnblation")

function onClicked()
	local Model = script.Parent
	Model.Button.ClickDetector.MaxActivationDistance = 0
	Model.Parent.Parent:WaitForChild("Sounds").Press:Play()
	TweenService:Create(Model.Button, TweenInfo.new(.3, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Size = Vector3.new(1.179, 0.082, 1.17)}):Play()
	task.wait(.3)
	TweenService:Create(Model.Button, TweenInfo.new(.3, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Size = Vector3.new(1.179, 0.033, 1.17)}):Play()
	Model.Indicator.BrickColor = BrickColor.new("Bright green")
	-- Fires to activate reactor startup sequence
	LaserEnablation:FireAllClients()
	Model.Activation.Disabled = true
end

wait(15)

script.Parent.Button.ClickDetector.MouseClick:Connect(onClicked)

Client side (StartPlayerScripts) I don’t know if I put it in the correct place

local function RunEvents()
	InGameEventStorage[1].OnClientEvent:Connect(function()
		print("[1] Received.")
		InGameEventStorage[1]:FireServer()
	end)
end

RunEvents()

Main server script (In workspace)

InGameEventStorage[1].OnServerEvent:Connect(function()
	-- codes
end)
2 Likes

Can anyone help me out with this?

2 Likes

So which RemoteEvent is firing multiple times?

2 Likes

The RemoteEvent that is firing multiple times is the LaserActivation aka Startup Sequence for the another name.

2 Likes

I don’t really see anything wrong with this though, from the 1st Script that you’ve provided. Could it be because the ClickDetector was being spam-clicked?

Were you intending this to fire only to one Player?

2 Likes

May I ask is there a specific requirement for making a new event connection within a function each time?
This could be prone to risks especially if this function gets called more than once as it will start creating multiple connections and stacking them whenever this function gets called.

Just to avoid the risk I would actually remove the connection from this function and if it’s needed to perform the logic from other places in the script then place the logic in a separate function instead.

local function DoSomething()
        print("[1] Received.")
	InGameEventStorage[1]:FireServer()
end

InGameEventStorage[1].OnClientEvent:Connect(function()
	DoSomething()
end)
2 Likes

If you’re sending an event from the server to the server, isn’t a BindableEvent better than sending to all clients and then each client sends a request to the server? Or are you doing anything in the client with this event apart from sending it back to the server?

EDIT: I decided it’s better to explain what I mean. In simpler words, a BindableEvent works the same way as a RemoteEvent, but instead of firing from server to client or client to server, it fires from server to server or client to client.

From what I understood, you just want to fire this event once, from the server, so another server script can handle enabling the lasers, right?

If so, this is definietly what you need, since it’s redundant sending the event to the client, if you do nothing in the client, and then send back to the server straight away. But correct me if I’m wrong!

2 Likes

I believe your issue lies here. You appear to be firing back to the server everytime OnClientEvent is called and because you’re firing on all clients it’ll fire back to the server depending on how many clients there are.

I’m not sure what you’re trying to accomplish but it looks like Server → Server communication. As the post above me said, you should be using a BindableEvent instead of a RemoteEvent. Bindable’s are fundamentally the same as RemoteEvents but allow for scripts to communicate on the same client-server boundary instead of opposites.

2 Likes

Yes, I want the remote events to fire once many players join the game. Thanks for your help! This helped me very much. I appreciated it.

2 Likes

That’s very helpful; thanks for your help! It works, I didn’t try using BindableEvent so, I kind of getting perplexed. Anyways, thank you.

2 Likes

Thanks for your reply; it helps me a lot, and it works now.

3 Likes

Yeah, I meant, when I tried firing the RemoteEvent, it might stack and send it multiple times; I figured it out. Thank you for sharing your answers.

2 Likes

In this circumstance, I wanted a player to press a button to fire all clients, not a single client; By the ways, I figured it out; Thank you for sharing, I appreciated it.

1 Like