I have a local script and a server script, they are linked together through a remote event in replicated storage. When I press the button, it should print out both messages.
Local script:
script.Parent.Screen.Frame.Button.Activated:Connect(function()
game.ReplicatedStorage.Hello:FireServer()
print("hello from client")
end)
Server script:
game.ReplicatedStorage.Hello.OnServerEvent:Connect(function(player)
print("hello from server")
end)
OUTPUT:
hello from client
Does it seem that the remote event never got fired?
I think I didn’t word my answer correctly, excuse me for that. What I meant was that messages printed from server are likely to not be replicated to client in game.
im talking about your RemoteEvent which only fires if certain options in studio is enabled, it would work fine in game,
also, it printing after :FireServer() doesnt proof that the remoteevent got fired,
I have another hypothesis, this may be caused due to Server binding OnServerEvent after Client :FireServer()s it. This issue is possible in ROBLOX Studio, as Studio has a weird script running order. In a real game, this issue will not happen as Server runs before Client.
You could also try to create the remotes from server, using :WaitForChild() in Client, and only set the Parent of the remotes once you’ve binded the OnServerEvent/OnServerInvoke events to a function.
I had an issue with this but the reverse - I was firing a remote event from the server but the client sometimes wasn’t receiving it. It seems like remote events that are used on startup need some sort of protocol to make sure the client is listening to it at the time it is called. Likely for you, the client is acting before the server. For longer client loading times, it may be the opposite, so I don’t think creating the event on the server will do much. It seems like RemoteEvent events aren’t cached, although I would have hoped they would be…
What I recommend is using a RemoteFunction to see if the script is listening to the event, since it yields until there is a response. Then you can fire the event. But that’s also feasible just using a RemoteFunction alone. I know RemoteEvents are a lot nicer in that they don’t yield, but it is probably necessary for any events that need to fire at the start of a game.
Im having the same problem but im using a gui and all my events are in a folder in workspace. I can fire the main event to announce a message but I cannot do any other event. Very Weird
local Hello = game:GetService("ReplicatedStorage"):WaitForChild("Hello")
script.Parent.Screen.Frame.Button.Activated:Connect(function()
Hello:FireServer()
print("hello from client")
end)
Script:
local Hello = game:GetService("ReplicatedStorage"):WaitForChild("Hello")
Hello.OnServerEvent:Connect(function(player)
print("hello from server")
end)