Hello there, I am making a game similar to Tower of Hell and I came across to an issue. My height bar is inaccurate.
Script:
local runService = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local towerHeight = tonumber(replicatedStorage.TowerHeight.Value)
runService.Heartbeat:Connect(function()
local character = workspace:FindFirstChild(script.Parent.Name)
if not character then return end
local hrp = character:FindFirstChild("HumanoidRootPart")
local leftLeg = character:FindFirstChild("Left Leg")
if not hrp or not leftLeg then return end
script.Parent.Position = UDim2.new(0, 0, 1 - ((hrp.Position.Y - (hrp.Size.Y/2 + leftLeg.Size.Y))/towerHeight), 0)
end)
replicatedStorage.TowerHeight.Changed:Connect(function(value)
towerHeight = tonumber(value)
end)
The calculation just needs to be a ratio restricted on [0, 1] between the vertical position of the player’s torso and the tallest point of the tower.
Your calculation should be something like this:
local tallestPoint = ...
local percentage = math.clamp(player.HumanoidRootPart.Position.Y / tallestPoint, 0, 1)
-- use percentage to place point
Think of the position of the height arrow as the top point of an invisible bar contained in the height display. Placing the arrow at the top of this invisible bar and scaling the bar using the percentage calculated should give the proper vertical player position.
Debug your code. See if tallestPoint is actually taking on the proper value. If it’s not, perhaps your issue lies in replication somewhere and the client simply cannot see the true Y-component of the position of the tallest point.
FYI: use task.wait() instead of wait.
Also use game.Players.LocalPlayer.CharacterAdded:Wait() to listen for the character spawning. CharacterAdded is an event, not a property, so the line
repeat wait() until game.Players.LocalPlayer.CharacterAdded
doesn’t make a whole lot of sense (when is an event true?)