Player.Character not working?

I have a problem with Player.Chararcter

My code:

local Players = game:GetService("Players")
local Character = Players.LocalPlayer.Character

Pls help me!

5 Likes

Try

local Character = Players.LocalPlayer:WaitForChild("Character")
local Character = Player.Character or Player.CharacterAdded:Wait()

If Player.Character is nil, the script will yield and wait until a character is set to the player.

3 Likes

The character is not a child of the player, it’s an ObjectValue property.

1 Like

Isn’t working:
image

game.Players.LocalPlayer isn’t useable in server scripts.

Your script isn’t working:
image

Then…I need a local script???

This is the error:

The best way to get the players character is using the following:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

This can only be used in a local script because I am using the LocalPlayer object. If you want to get the players character in a server script then you just use:

local Player = game.Players.supergreatr299 -- This is just an example of my username
local Character = Player.Character
3 Likes

You can also do this in a server script:

local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
   local char = plr.Character or plr.CharacterAdded:Wait()
   --do whatever
end)
6 Likes

The error is happening because if this is a server script and you are trying to get the local player which is not possible

1 Like

Thank you so much!!! :slight_smile: :slight_smile:

the way to make it in a variable is:

local player = game:GetService("Players")
local char =  player.Character or player.CharacterAdded:Wait()

-- [[ You can do anything else here ]] --

This won’t work. You’re trying to get the character from the player service, not the actual player.

local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()

This is the best way to do it since you wait for the player to load also. And the player object belongs to the main scope of the script.