Why is LocalPlayer.Character not working?

For some reason this following line of code is not working:local player = game.Players.LocalPlayer.Character
Its in a local script why is it not working?

The problem may be because there is no actual character yet.

1 Like

How would i solve this? :waitforchild?

You wouldnt use :WaitForChild because the character isn’t actually the child of the Player. What you would probably use is

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)

end)

the problem is i want player to be a variable not to trigger a function.

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)

if you look where it says function( right after that it says character. That would be the variable for the character, you can test this by maybe doing something like

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
print(character.Name)
end)

for example

oh ok then using character as my variable not player?

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

This should work.

You can use player if you replace game.Players.LocalPlayer.CharacterAdded:Connect(function(player)
character with player, or whatever variable you want it to be.

Honestly, no point of doing this when you could just use the solution above, which would ensure the loading.

the problem with this is that is says “Humanoid is not a valid member of Model “Workspace.hellobeede”” (hellobeede is my accounts name) so i think it hasnt loaded yet

Ensure that the Humanoid exists, waitforchild it and before doing anything.

local hum = character:WaitForChild("Humanoid")
local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
if hum then
	print("Humanoid Found")
	-- Resume Function --
end

The code I sent you ensures that the character loads, so I am guessing you are either doing something wrong or its roblox’s engine, as I use those variables for every script related to character in the client, and they work.

thanks this seems to work. the reason I got the error before is because I forgot to add waitforchild. Thanks you saved me a lot of time

No problem, usually it doesn’t even require the WaitForChild, my guess is that you are using Workspace.StreamingEnabled

Good luck!