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
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
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
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.
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
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.