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

Why can't I get the position of the Player?

Asked by 4 years ago

This is what I got

player = game.Players.LocalPlayer.Character.HumanoidRootPart.Position.X
print(player)

When I run this I get an error saying something about the Character. Why does this happen?

1 answer

Log in to vote
0
Answered by 4 years ago

You should check if the player's character exists first, if you are running the script immediately when the game starts then there is a good chance it will be executed before the player spawns

local Character = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:Wait()
local Position = Character.HumanoidRootPart.Position.X
print(Position)
Ad

Answer this question