Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

I am trying to reference the player. It's not working?

Asked by
N43FGXL 169
5 years ago
Edited 5 years ago

I am attempting to reference the player through game.Workspace[player.Name] . It's not working, why is this?

game.Players.PlayerAdded:Connect(function(player)
    print(game.Workspace[player.Name].Name) -- Printing name of player in workspace.
end)

My username is N43FGXL and I get the error: N43FGXL is not a valid member of Workspace When I check the explorer, the model of my character is in the workspace...

2 answers

Log in to vote
1
Answered by
compUcomp 417 Moderation Voter
5 years ago

You are confusing the player and the character. The character is the player's physical representation in-game. Just because the player has joined doesn't mean their physical appearance has loaded. To do what you described:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function (char)
        print(char.Name) -- char is equivalent to workspace[player.Name]
    end)
end)
Ad
Log in to vote
0
Answered by 5 years ago

You are over complicating things. It's actually quite simple!

game.Players.PlayerAdded:Connect(function(player)
    print(player.Name)
end)
0
I'm trying to find the character in the workspace. I just had an example. N43FGXL 169 — 5y

Answer this question