Any ideas in how I could make the Gui move whenever the character moves too?

Hey, guys! So today I’ve been thinking ways in how I could make it so when the Player’s Character jumps the ImageLabel’s Y axis position increases with it, its similar to the GUI in Tower Of Hell right here
image

I was wondering as well by the fact that the developer would have used Renderstepped to smoothly make the GUI increase in the Y axis position. Right now, I’ve obviously got a ImageLabel with the Player’s picture on it using the Players:GetUserThumbnailAsync function
image

but I wonder if any of you would know how to do this, I know by the fact that RunService definitely takes place here but I am not 100% used to it so hopefully I get to know it fully when I find a solution.

If you still don’t understand what I’m trying to say:

Basically, I am trying to make the Gui’s position to change whenever the character jumps.

Yes, RunService will come to the rescue here:

local rs = game:GretService("RunService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")
local min, max = 2, 2300 --min and max height
local img = script.Parent.ImageLabel --image label

rs.HeartBeat:Connect(function() --every frame after physics calculations

    local pos = hum.RootPart.Position.Y
    local fraction = math.clamp( pos / (max - min), 0, 1) --[[0 to 1 because scale position in UIs; so 
if the number is out of bounds, just clamp it down/up to the
 closest valid number (0 or 1)]]

    img.Position = UDim2.new(0.5, 0, 1 - fraction, 0) --1 - fraction because it's from bottom to top while position runs from top to bottom (inverse it)

end)
4 Likes

Using RenderStepped for this isn’t really a good idea: Heartbeat is more appropriate since what is desired to be achieved is relying on physics, as the event fires after every physics update of a frame. RenderStepped fires before a frame is rendered (drawn), and not using RenderStepped accordingly can cause performance issues

2 Likes

I don’t seem to get this line, I mean I know what math.clamp does it just returns the X value depending on the min and max but could you please clarify what your trying to do if you can, like why do you divide it and not times it?

We need a number between 0 and 1.

So, if we divide part by whole, then we get that. “Part” is the Y position of the HRP, and the whole is the valid range min to max (hence why we subtract). Min won’t always be 0 (IDK about your game, but in general cases).

If the Y position is 5 and the allowed range is from 2 to 12, then it would be 5/10 or 0.5 as the GUI position (right in the middle).

Do you get it now?

1 Like

Yeah, I slightly get what you mean, although I’ll come back to this tomorrow as I have lack of energy right now, thanks for the help, though!

1 Like

Wow! I’m so proud of myself honestly, I’ve been trying and trying to find a way where I could make the GUI faster so I decreased the MAX number to about 20 and now it moves smoothly as expected, thank you so much!

I also got confused thinking that the MAX and MIN height is meant for the HRP’s Y position but it was actuallly the GUI, I also love the way you used the inverse, it definitely makes sense, yep.

1 Like