Getting joining players in LocalScript

I want to do something to each player when they join that’s only locally visible, so for testing I just print the names. But it prints nil each time.

ServerScript: (in ServerScriptService)

local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

Players.PlayerAdded:Connect(function(player)
ReplicatedStorage.onSpawn:FireClient(player)
end)

LocalScript: (in StarterCharacterScripts)

local Teams = game:GetService(“Teams”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)

ReplicatedStorage.onSpawn.OnClientEvent:Connect(function(player)
print(player)
end)

(the onSpawn RemoteEvent is in the ReplicatedStorage)

2 Likes

the player argument only sends it to the player, which is not sending any data, in order to get the name of the player, you have to pass the player.Name as a second argument:

	ReplicatedStorage.onSpawn:FireClient(player, player.Name)
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.