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
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.
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 @deathcharge415 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.