Remote Event Running two requests at the same time

I have 2 text buttons that have call the same remote event but request different things.
When I write in the server script just one of the two requests, it will work just fine, but when I try adding both, it’ll either run both of the scripts at the same time when I clicked only one button, or it’ll run one of the requirements when I click either button.

I would make two remote events if I needed to do only 2 commands. I need to make 100 of these, which is why I went with this route.

}
--Attempt one. When I click either of the two buttons, both prints will show in the output at the same time.
--I want it so that if I click button one, one 1 print will show, and if I hit button two, the second print will show. 
Event.OnServerEvent:Connect(function()
	if (Requests["Zone1Test"]) then
		Requests["Zone1Test"]()
		print("1 Reaced the server")
	end
	
	if (Requests["Zone2Test"]) then
		Requests["Zone2Test"]()
		print("2 Reaced the server")
	end
end)
--Attempt two, when clicking either button, only the first print will show. 
Event.OnServerEvent:Connect(function()
	if (Requests["Zone1Test"]) then
		Requests["Zone1Test"]()
		print("1 Reaced the server")
	elseif (Requests["Zone2Test"]) then
		Requests["Zone2Test"]()
		print("2 Reaced the server")
	end
end)

If there’s any confusion, I’ll explain it more of course.

1 Like

If you want to use the same remote then send a parameter to the server to check against the Request dictionary.

1 Like

Can you show an example? You don’t have to do it for me, it can just be a mock to show me what you mean

1 Like

so when you send a remote you can send parameters like so:

Event:FireServer("hello")

then you can define the parameter in the function of the OnServerEvent connection

Event.OnServerEvent:Connect(function(player, param)

Note: when the server is receiving an event the player param is always before the rest of the params.

I see what you mean, but each function in the request dictionary is lead to a different part so I can’t just use the same function and define the parameter because I need the aimed part defined as well (Unless I’m able to do that with the parameter as well. I’m no good in this field so I wouldn’t know)

You can just index a part with the param sent from the client.

I don’t understand sorry (adding this for extra characters)

By chance you have called Event.OnServerEvent:Connect more than once? If so, you must disconnect the connection before creating another connection.

Not at all. That’s the only one.

From the looks of it, it seems like Requests["Zone1Test"] is true which results in the first print always running. Maybe try setting that statement to false so the second print statement can print.

Event.OnServerEvent:Connect(function(player, zoneTestString)
	if (Requests[zoneTestString]) then
		Requests[zoneTestString]()
	end
end)
1 Like

well, I need them to print at the click of a button so wouldn’t changing that to false be making that unusable?