I have some code that teleports the player to their x position, y position and 0 on the z axis if they move off 0 on the x axis, but It’s not working.
I’ve figured out that it’s the trigger that it’s the if statement not working, but I’m not sure how to fix it
Here’s my code:
while true do
wait()
if not char:WaitForChild("HumanoidRootPart").Position.Z == 0 then
char.MoveTo(Vector3.new(char:WaitForChild("HumanoidRootPart").Position.X, char:WaitForChild("HumanoidRootPart").Position.Y, 0))
end
end
Edit:
“char” is game.Players.LocalPlayer.Character
-- LocalScript in StarterCharacterScripts
local runService = game:GetService("RunService")
local character = script.Parent
local rootPart = character:WaitForChild("HumanoidRootPart")
runService.Heartbeat:Connect(function(deltaTime)
rootPart.CFrame = rootPart.CFrame.Rotation + Vector3.new(rootPart.Position.X, rootPart.Position.Y, 0)
end)
and here is a demo project showing the character locked at 0 on the Z axis