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

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

Asked by 1 year ago

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 answer

Log in to vote
1
Answered by 1 year ago

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 — 1y
0
If you're talking about `WaitForChild`, then yes. DindinYT37 246 — 1y
0
using the `while true do` loop without wait() will crash T3_MasterGamer 2189 — 1y
0
but if you use the `while true do` loop USING wait() won't crash T3_MasterGamer 2189 — 1y
0
I haven't mentioned that because I consider using `while true do` with `wait` as `while wait() do` instead. DindinYT37 246 — 1y
Ad

Answer this question