0

# I'm trying to make a TextLabel that says how high I am, but it doesn't show, how I fix this?

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?

1

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

0
Does it also work for a leaderstats script? RektwayYTB 123 — 23d
0
If you're talking about WaitForChild, then yes. DindinYT37 212 — 23d
0
using the while true do loop without wait() will crash T3_MasterGamer 1701 — 22d
0
but if you use the while true do loop USING wait() won't crash T3_MasterGamer 1701 — 22d
0
I haven't mentioned that because I consider using while true do with wait as while wait() do instead. DindinYT37 212 — 22d