Hello! So I am currently trying to make a game like Steep Steps and I want to know how to make a meter counter. I am not the best scripter, so what I did didn’t work. So how would I go about doing this? Thank you for your time and feedback. Have a great day!
You just keep track of the player’s Y position. Roblox uses studs as the unit of length, and the correct conversion from studs to meters is controversial, so it’s up to you.
This is just an example; it prints out the altitude (distance from sea level which is when Y is 0) of the player every half second:
local lp = game:GetService('Players').LocalPlayer
--get the player's character model
local char = lp.Character or lp.CharacterAdded:Wait()
local hrp: BasePart = char:WaitForChild('HumanoidRootPart')
--whenever the player respawns, we need to reset the variables as well to their new model
lp.CharacterAdded:Connect(function(newChar)
char = newChar
hrp = newChar:WaitForChild('HumanoidRootPart')
end)
local debounce: number = 0
game:GetService('RunService').Heartbeat:Connect(function(dt)
debounce += dt
if debounce >= .5 then --every 0.5 seconds
debounce = 0
print(`Altitude: {math.floor(hrp.Position.Y + .5)}`) --rounded to the nearest whole number
end
end)
What I’m wanting is where as the player gets higher climbing the hill, the text of a label goes up by 5. Does that make sense? What would that look like? Keep in mind I’m not the best scripter lol.
For that, you can round the number to the nearest 5 with this syntax:
math.floor(number / ROUND_TO) * ROUND_TO
And getting it to display as a text should be trivial, you just set a TextLabel’s .Text
property to the altitude.
I made a demo for you, you can play around with it:
Altimeter.rbxl (51.9 KB)
For some reason, my label does this:
I don’t think my code is wrong:
local TextLabel = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart: BasePart = Character:WaitForChild("HumanoidRootPart")
Player.CharacterAdded:Connect(function(newCharacter)
Character = newCharacter
HumanoidRootPart = newCharacter:WaitForChild("HumanoidRootPart")
end)
game:GetService("RunService").Heartbeat:Connect(function(dt)
TextLabel.Text = `<b>Meters:</b> {math.floor(HumanoidRootPart.Position.Y * .2) *5}`
end)
Do you have RichText enabled on the label?
That fixed it! Thank you so much!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.