Remote Event not being picked up by the Server

Hello! I am facing an issue, when I fire a RemoteEvent the server isnt picking up. I tried debugging using print() and I identified that the .OnServerEvent is not running but the RemoteEvent is being fired. No errors

Here’s the Server Script

local CS = game:GetService("CollectionService")

for i, v in pairs(CS:GetTagged("Part")) do
   local RemoteEvent = v:WaitForChild("RemoteEvent")
   print(RemoteEvent.Name, RemoteEvent.ClassName, RemoteEvent.Parent.Name) --Prints everything normally
   RemoteEvent.OnServerEvent:Connect(function()
      print("Hello World!") -- Doesnt print
   end)
   print("roblox") --Prints
end

Local Script:

local RemoteEvent = script.Parent.RemoteEvent
print("1") --Prints
script.Parent.Activated:Connect(function()
    RemoteEvent:FireServer()
    print("2") --Prints
end)

What happens if you add a wait (e.g. task.wait(5)) before firing the event? Maybe the server didn’t connect the event in time and the client fired the event too quickly.

Also, are you sure you’re firing the correct event? In the localscript it looks like you’re firing an event stored in Replicated Storage, but in the server script it looks like you’re listening for an event to be fired that was in a part.

Try referencing the remote event outside of the for loop.

Oh sorry, I put a different script. Im facing the same problem with two server-client systems and i mixed up both of them.
Lemme edit the post and put the same scripts

Everything looks correct based on your debugging. The only thing I can think of is that perhaps the remote event you’re triggering is different from the one on the server. That might be the case if you replace the parent part on the client with a client copy.

Another case where that might happen is if you’re cloning the parts. It also might be the case if the parts don’t start out tagged. (The loop only runs over the stuff tagged “Part” that exist initially, so anything added doesn’t get the connection created for it.)

An easier way to do this might be to have a single remote event in replicated storage, then have all the client scripts inside the parts fire that remote event along with their parent’s parent. Then on the server side just check that the sent instance is valid (has the tag) and use it for your code.

I have to agree with @ne3ulimity here. It seems the server may not be connecting to the event fast enough. Try waiting a small amount of time. Also make sure that the event you’re firing is the correct event that you’re listening for.

Also, RemoteEvents pass in a Player argument automatically, but you need to account for this.

local remote = lorem.ipsum -- Remote Event Path

remote.OnServerEvent:Connect(function(player: Player)
    -- Do something here
end)

PS: You do not have to add in the player type, I usually just do that just because I can.

References:
Remote Events and Callbacks | Documentation - Roblox Creator Hub

Im 100% sure its the same remote event

Thanks it works

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.