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

How to find a player in workspace by finding the localplayer?

Asked by 8 years ago
local player = game.Players.LocalPlayer.Name --Find Player name
local nameofplayer = game.Workspace:FindFirstChild(player) --Get the player in workspace 

if script.Toggled.Value == 1 then

print(nameofplayer)

end

Error (Line 2): Argument 1 missing or nil

0
You can get a Player's Character by the 'Character' property of a Player ( Player.Character ). :) TheeDeathCaster 2368 — 8y
0
Can I have an example? Or a revision to my original script? User#6200 10 — 8y

5 answers

Log in to vote
2
Answered by 8 years ago

Maybe this will work

local player = game.Players.LocalPlayer --Find Player name
local nameofplayer = player.Character.Name--Get the player in workspace 

if script.Toggled.Value == 1 then

print(nameofplayer)

end

0
All localPlayers have names, and the workspace player model names are the same. ILostMyAccount2Tims 0 — 4y
Ad
Log in to vote
0
Answered by 8 years ago

Is this in a localscript? It seems like it isn't if it's finding player as a nil value. If it is in a localscript, it may be firing too fast before the character/player actually loads.

If you're simply looking for a name, a revision to ghost's script; you don't need the name of the character since it simply inherits it from the player object. Just pull the name from the player object you already defined.

local player = game.Players.LocalPlayer 

if script.Toggled.Value == 1 then
    print(player.Name)
end
Log in to vote
0
Answered by 8 years ago

I'm guessing you want to find the character of the player, in order to make it work on a server and not just in studio you must get player with this.

local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
end

"character.Name" is the the player's name.

Log in to vote
0
Answered by 5 years ago

Change it to this:

local player = game.Players.LocalPlayer.Name --Find Player name local nameofplayer = game.Workspace:FindFirstChild(player:FindFirstChild("Character").Name) --Get the player in workspace

if script.Toggled.Value == 1 then

print(nameofplayer)

end

0
local nameofplayer = game.Workspace:FindFirstChild(player:FindFirstChild("Character").Name) hawkinator8554 -2 — 5y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

LocalPlayer names can be accessed with: local plrName = game.Player.LocalPlayer.Name And the character can be accessed with local character = workspace:WaitForChild(plrName) Hope that helps.

Answer this question