Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make a GUI update every time a players Y axis increases by 6 studs?

So I am trying to make a depth counter and I need the depth to increase by one every time the players Y axis is increased or decreased by 6 studs. Everything else works.

Ignore where it subtracts the big number, that is so the depth says 0 when spawned in.

local player = game.Players.LocalPlayer
while wait() do
	local playerDepth = math.abs(math.floor(player.Character.HumanoidRootPart.Position.Y - 16417.1))
	script.Parent.Text = "Depth: "..playerDepth
end

1 answer

✓ Accepted answer

Simply divide the number by six and get the floor. For example:

52

We divide this by six, so it tells us how many times we've increased our distance by six.

52 / 6

This gives us 8.6666_.

Now, since this is almost always gonna be a non-integer, we take the floor to get a nice round number.

floor(52 / 6)

This gives us 8.

Lua-u version

local value = <whatever value you want to measure>

local increment = <whatever increment you want, 6 in your case>

local result = math.floor(value, increment)

If you want to you can also take the absolute value of your result, so that the number is always positive.

1 comment

0

I don't understand

This discussion is preserved as it was. New answers, comments, and votes are closed.