Still have questions? Join our Discord server and get real time help.
Log in to vote

Why doesnt this check for the humanoidrootpart.z position and teleport me to another position?

Asked by 3 months ago
local plr = game.Players.LocalPlayer

local hum = plr.Character.HumanoidRootPart

if hum.Position.Z == 4530 then


hum.CFrame =, 65, 4530.58984)

elseif hum.Position.Z == 5110.58984 then


hum.CFrame =, 65, 8356.58984)

elseif hum.Position.Z == 9499.89258 then


hum.CFrame =, -359.6, 9525.3958)


local strength = plr.Character.HumanoidRootPart.BodyForce

strength.Force =, 0, 2000)

game.Workspace.Gravity = 0

plr.Character.HumanoidRootPart.CFrame =, 53, 163)


btw if u want me to indent this then i tell u now, idk what indent is or how to do it

no errors and no prints Gameplayer365247v2 551 — 3mo

1 answer

Log in to vote
Answered by 3 months ago


  • You need to link an event or loop with these if statements

Your script only runs/triggers once when the game has loaded. If you link it with an event/loop, it'll check these if statements multiple times and achieve what you want.

  • Don't check if decimal values are equal to each other (unless you know what you are doing)

Even if we linked this script up with an event, it will never run. Why? Because you are comparing decimal values of positions.

The position might say '1.000', but in reality it shows up as '1.000000001' or something similar along those lines. With that in mind, the script will never run because 1.000 doesn't equal 1.000000001.

How to improve what you are trying to achieve

  • Use magnitude

Magnitude is the distance in studs between two vector points. If you want the player to be in a certain area to teleport them, check if they are in a magnitude of an area, then teleport them.

  • Use :Touched() event

Rather than checking if they are in a certain Z position, use a part and apply a touched event to a part and teleport them accordingly

  • Use greater than and less than

This will be more consistent than checking if it's equal as you are allowing for more tolerance for your if statements to trigger.

Hope this answers your question or gives you a better alternative!

":Touched()"? That's not a method. BashCaster 2170 — 3mo

Answer this question