Server To Client Remote Events not working

I don’t really have a game and I’m just practicing how to code and I’m trying to use the remote events. I made it work from client to server. However, my server to client side doesn’t work. I don’t get any signals for the client script. It doesn’t give me output errors as well.

–ServerScriptService
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
game.ReplicatedStorage.ServerTest.OnServerEvent:Connect(function(player)
print(“Server Signal”)
game.ReplicatedStorage.ClientTest:FireClient(player)
end)
end)
end)

THIS IS WORKING, it prints “Server Signal”.

–StarterPlayerScripts (Localscript)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
game.ReplicatedStorage.ClientTest.OnClientEvent:Connect(function(player)
print(“Client Signal”)
end)
end)
end)

THIS IS NOT WORKING, it doesn’t print anything. Any suggestions? Thanks!

PlayerAdded won’t fire for your LocalPlayer in StarterPlayerScripts because the scripts load after your player already exists

OMG, works perfectly fine. As I said, I’m just practicing at scripting so I thought I have to use player added again for the client script. Thank you!

Also you shouldn’t be connecting new OnServerEvent and OnClientEvent signals everytime someone respawns, it’s enough to do it once.
ex:

Server Script:

-- whenever anyone contacts the server from their client, this fires
game.ReplicatedStorage.ServerTest.OnServerEvent:Connect(function(player)
	print("Server Signal from", player)
	-- make the server send data back to the client that contacted the server
	game.ReplicatedStorage.ServerTest:FireClient(player, "Hello from the server")
end)

LocalScript

-- contact the server from the client
game.ReplicatedStorage.ServerTest:FireServer()

-- listen to what the server tells to the client
game.ReplicatedStorage.ServerTest.OnClientEvent:Connect(function(text)
	print(text)
end)

image
Just 1 remote event is enough to do all of this

2 Likes