I am trying to communicate between a server Script and a Local Script using RemoteEvents, but I have been unable to get the client side script to fire.
-- Server Script:
MiniEvents.Start:FireAllClients({},1)
print("Sent")
-- Local Script:
MiniEvents.Start.OnClientEvent:Connect(function(vals,num)
print("Received")
end)
print("Run")
In the above code MiniEvents is a ModuleScript which defines the RemoteEvent Start
There are no error messages, and “Run” is output before the section of code that fires the remote event is run. When the remote event is fired, “Sent” is output as expected, but “Received” is never output.
I am aware this may be a result of running the scripts locally in Studio (ie. using F5), but if it is, the problem and possible fixes are not well documented.
I would mostly just like to know if the mistake is in my implementation, or whether it’s a problem with how the code is being run.
As far as I can tell it’s not a problem with loading the module. I ran a quick check, and Start is not Nil at either of those points. I also don’t think it’s a problem with referencing the wrong event, as I don’t have any other variables named Start
your code looks good theres no reason for it to not work, so there must be some mistake with the start variable or what it = 's to or something else.
Do you think you could send in a file for me to test? Just include the remote events, firing code, and receiver code and then whatever variables needed
I tbh don’t get it but when I manually put a remote event it works fine.
the one I use a hybrid of using instance.new, it generates 2 remotes for some reason?
Also I just experimented that everytime a script requires the module, it generates a new remote event so thats probably why its not receiving properly, both scripts are using two different remotes.
Ah, I think I see what’s happening now.
Accoring to the ModuleScript | Roblox Creator Documentation Documentation, “ModuleScripts run once and only once per Lua environment”. Server and Client aren’t the same Lua environment, so the script actually runs twice. My Assumption was that the ModuleScript would only run once in total, returning the same events to both client and server.
So it’s just a matter of creating a RemoteEvent that’s not dependent on the ModuleScript, ie. as an independent object in ReplicatedStorage