How to make a height bar? Just in like Tower of hell

Hello I just tried this script to make a height bar but it seems to not work
Anyone can help me fix the issue? Thanks

They are both LocalScripts in ScreenGUI > Frame > ImageLabel

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:FindFirstChild("PlayerGui")

if Player:FindFirstChild("PlayerGui") then
    while wait() do
        local ImageLabel = PlayerGui.HeightGui.Frame:FindFirstChild("ImageLabel")
        local Character = game:GetService("Workspace")[Player.Name]
        local PrimaryPart = Character:FindFirstChild("UpperTorso") -- Torso for R6, UpperTorso for R15
        local Height = math.ceil(PrimaryPart.Position.Y)
        ImageLabel.Position = UDim2.new(0, 0,0 - Height / 50, 0) -- Change 50 to another to adjust height
    end
end

And

local ThumbnailType = Enum.ThumbnailType.HeadShot

local ThumbnailSize = Enum.ThumbnailSize.Size48x48

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

while wait() do

script.Parent.Image = Players:GetUserThumbnailAsync(Player.userId, ThumbnailType, ThumbnailSize)

end
2 Likes

Can you upload screenshot on how it looks now?

Also I think you should rename “PrimaryPart” to something else, and also find HumanoidRootPart, not the upper torso(that’s because the bar will shake a bit, cuz its moving when you are walking)

2 Likes

while true do
	wait()
	local PlayerCharacter = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	if PlayerCharacter ~= nil then
		script.Parent.Frame.Visible = true
		local Pos = ((PlayerCharacter["HumanoidRootPart"].Position.Y - 2.825)/50) * script.Parent.Frame.AbsoluteSize.X
		script.Parent.Frame.ImageLabel.Position	= UDim2.new(0,Pos,0,0)
	else
		script.Parent.Frame.Visible = false
	end
end

bar.rbxl (21.6 KB)

1 Like

Hi,
Instead of doing

local Character= game:getService("Workspace")[Player.Name]
local PrimaryPart= Character:FindFirstChild("UpperTorso")

Try doing the following:

local character= Player.Character
local PrimaryPart= character.PrimaryPart

Wait the bar is not going up-down, and you are moving Y position in it. I think you should change it to X

1 Like

Renaming didnt worked, but thank you!

Please add a space before the equals sign.

You’re trying to set the Y value of the image label, when you should set the X value and make it go to the right when you go up

Why are you using 2 localscripts? And why update the image every wait() in a while loop?

There’s no need to add a space before the equal sign, if you want to do it for “making the code look clean”, you can do it; but if you dont want to, you dont need to.

That didnt worked its still stuck in the place

That doesn’t really matter, I don’t think it will fix issue

1 Like

Yeah, it looks cleaner like that and it’s a good habit to make code look clean.

Yeah im really annoyed when like:

local hello="world"

but anyways lets look back to the issue

Try also to avoid to use wait(), since wait() has a variable time. On slower servers/devices wait() can have a longer duration than expected. I’d recommend if you’re on the client, that you wait for the renderstepped/heartbeat/stepped event. Also, I’d also recomend instead of getting imagelabel, character and primary part each time you run the loop, you get those before the while, since you dont need to calculate those each time. The same applies to

script.Parent.Image = Players:GetUserThumbnailAsync(Player.userId, ThumbnailType, ThumbnailSize)

If you think about it, you only need to calculate that one time.

1 Like

Woah thats a long explanation, would this fix the issue or make the game less laggy for slow devices?

1 Like

It wouldn’t fix the issue, just make performance better.

1 Like
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:FindFirstChild("PlayerGui")

if Player:FindFirstChild("PlayerGui") then
    while wait() do
        local ImageLabel = script.Parent.Frame:FindFirstChild("ImageLabel")
        local Character = game:GetService("Workspace")[Player.Name]
        local PrimaryPart = Character:FindFirstChild("UpperTorso") -- Torso for R6, UpperTorso for R15
        local Height = math.ceil(PrimaryPart.Position.Y)
        ImageLabel.Position = UDim2.new(0, 0,(0 - Height / 50), 0) -- Change 50 to another to adjust height
    end
end

As you can see, I don’t used PlayerGui, just script.Parent

1 Like

Well, in this case it wouldnt do alot doing it one way or the other. But when you only need to get things 1 time, you dont need to calculate them all the time. Also sometimes if you’re using some roblox api calls, if you request too much of them too quickly, you may pass the rate and have that return nil. So its always good to “calculate”/get things the number of times you need them. And as for wait(), its good to try to avoid it at all cost.