Still have questions? Join our Discord server and get real time help.
1

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

local plr = game.Players.LocalPlayer

local hum = plr.Character.HumanoidRootPart

if hum.Position.Z == 4530 then

print("hit")

hum.CFrame = CFrame.new(-51, 65, 4530.58984)

elseif hum.Position.Z == 5110.58984 then

print("hit")

hum.CFrame = CFrame.new(-53, 65, 8356.58984)

elseif hum.Position.Z == 9499.89258 then

print("hit")

hum.CFrame = CFrame.new(-60.965944, -359.6, 9525.3958)

wait(5)

local strength = plr.Character.HumanoidRootPart.BodyForce

strength.Force = Vector3.new(0, 0, 2000)

game.Workspace.Gravity = 0

plr.Character.HumanoidRootPart.CFrame = CFrame.new(-123, 53, 163)

end


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

0
no errors and no prints Gameplayer365247v2 166 — 10d

0

Problems

• 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.