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

how do I find a player in workspace with player.Name?

Asked by 4 years ago

I tried to do it this way and it didn't work. whats the correct way?

local char = game.Workspace.Player.Name

3 answers

Log in to vote
2
Answered by 4 years ago

The only foolproof way to find a player in the Workspace is to use GetPlayerFromCharacter() on the model that you assume is the player's Character. Furthermore, you'd be using FindFirstChild() before this to check if there is something in the Workspace with the player's name. Now, this is not a site where we give you code; we help you with existing code. As such, this is all I'm giving you.

Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

If you are using a local script then you can just do:

local player = game.Player.LocalPlayer

local plr = game.Workspace:FindFirstChild(player.Name)

Log in to vote
0
Answered by 4 years ago

There's a property in the Player named Character which will give the model instance or nil. Sample of using Character

local Player = game.Players:FindFirstChild(name)

local char = Player.Character

Answer this question