Running a function when player goes up a certain height

What I’m going for here is for a function to run when the player reaches a certain height above the saved position of where the player was when it ran the function previously.

For example, if a player exceeds 200 studs or higher above the last saved position where the function was previously run, then said function would damage the player, and then save the position (preferably the Y pos) of where the function was run.

Note: English is not my first language, so forgive me if I sound confusing.

Does this help you? Edit: forgot to put the position after the humanoidRootPart.

local height = (previousPosition - humanoidRootPart.Position).Y
if height > 200 then
yourFunction()
end

And I’m assuming the function would include setting the value of previousPosition to the current position of the HumanoidRootPart?

I think so.

I’m not sure if you have a built-in function already, but hopefully, it works. If you’re unsure how to set it up, you can send the codes here or in the PM.

No worries, I think it’ll probably work out.

1 Like