OnClientEvent is broken?[SOLVED!]

Hello, my fellas,

I’m trying to make simple main menu script, but it don’t work. I think the RemoteEvent.OnClientEvent is broken. I tried to fire it from the server script located inside ServerScriptService and print something like "A", but nothing happen. Idk what else to do now. Please help me fix it.

LocalScript(MenuClient)
image

ModuleScript(Player)
image

Output: image

I posted about this yesterday and ended with me giving up and decided to rewrite the scripts… and still didn’t work. :pensive:

Cheers,
UncleDev

The MenuClient script is inside the StarterGui/PlayerGui

image

You said that the server code that you provided was in a ModuleScript, correct? Because if the server code you provided is in a Module script just like that, it won’t work. You need that server code in a regular script, then it should work. That worked for me.

Put it in a pcall, and print out the first + second value, and put the results here.

I Believe the issue is caused by the Player:LoadCharacter() which destroys the local script, here is the setup:

Simple setup,
image

local event = game.ReplicatedStorage.RemoteEvent

game.Players.PlayerAdded:Connect(function(player)
	print("Server")
	print(player)
	event:FireClient(player,"Test","Hello1234")
	player:LoadCharacter()
end)

Local script in starterGUI

local event = game.ReplicatedStorage.RemoteEvent

print("Local")
event.OnClientEvent:Connect(function(...)
	print(...)
end)

then the prints:

Notice how it prints what the remote event is sending once, however the second time it stops, because the message was only sent once towards the GUI that was destroyed because the player reset by player:LoadCharacter
image

Anyways if you want the menu to load only once upon player added why not just store a BoolValue or attribute within the local player?

2 Likes

Incorrect. A module script which executes code on the server behaves the same as if it were a normal script.

1 Like

Actually, module scripts inherit the context level of the script that originally required them. Meaning a module in replicated storage being required by a local script will be instantiated and run locally. Similarly, if a server script requires the same module, it will run that module on the server side.

1 Like

Yes, I forgot to show the whole script bc I thought it was the OnClientEvent problem. thx for your help :slight_smile:

NP, make sure to mark it as a solution in order to prevent other people from getting confused and replying to the problem.

image