Hello, I am trying to fire a remote event for when a player joins. This is my code
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
game.ReplicatedStorage.RESET:FireServer()
print("test")
end)
This is a LocalScript in the workspace and the print function isn’t even working so I know its not an issue with the remote event but rather that its never even being loaded in.
Why would you fire an event if it’s already on the server? If you want another script to activate, use BindableFunctions. Also, as @D0RYU rightfully said, it has to be on the server, not on the client (i.e. a normal script).
You can’t use FireServer() and OnClientEvent on the Server Side, as that’s only possible for the client
You CAN however use a FireClient() function if that’s what you mean
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
game.ReplicatedStorage.RESET:FireClient(player)
print("test")
end)
Also,
LocalScriptscannot run in the workspace, you have to reference them from the client’s perspective (Change it to a server script instead in ServerScriptService)
The problem is your using a Local script, The local script wont run because its on the client and cant see when a player joins. I would transfer the code to a server script and it should run just fine…
Local scripts are cloned on each client, so 2 for Player2 and Player3, so if they really detected other players, Player3 should print twice since there’s two scripts “detecting” (P2 and P3) players. Either way it’s better to do this on the server
The output is from the client’s own output. It only prints each player one time because the output is local to that player only. Aside from that, I do agree that stuff that needs to be done on the server should be handled solely by a server script.