So I'm making a game where you need to go as high as you can and for some reason the text label (which says how high is my HumanoidRootPart) and it just errors this:
Players.iMakeGames007.PlayerGui.ForHeight.HeightMeterz.LocalScript:5: attempt to index nil with 'Position'
while true do local Player = game.Players.LocalPlayer local Character = game:GetService("Workspace")[Player.Name] local hrp = Character:FindFirstChild("HumanoidRootPart") script.Parent.Text = "? "..hrp.Position.Vector3.yAxis end
How can I fix this?
First, using while true do
will simply crash your game.
Second, that's, as far as I know, not how a Vector3
works. Even if you were trying to get yAxis
it should've been hrp.Position.yAxis
. You should simply do hrp.Position.Y
.
The error you have provided seems to say that HumanoidRootPart
does not exist in the Player's character. I recommend trying to use :WaitForChild
and changing hrp.Position.Vector3.yAxis
to either hrp.Position.Y
or hrp.CFrame.Y
.
For example:
while task.wait(0.1) do local Player = game.Players.LocalPlayer local Character = Player.Character local hrp = Character:WaitForChild("HumanoidRootPart", 30) -- Adding 30 as an argument tells the method to only wait for 30 seconds, this prevents infinite-yielding. script.Parent.Text = "? " .. hrp.Position.Y end