So i'm trying to make a telekinesis tool, it uses BodyPosition to move the selected part around.. and it works but there's a problem. I have a conditional statement, where if the mouse's hit position is further away from the specified limit then the position shouldn't go any further away. Now the strangest this is that that bit works, but with the conditional then after it goes past the limit, the position automatically makes the X axis 0 for some unknown reason. I want to know how I can make the new position match up with the mouse's X axis, but still have the Z axis limit. Any ideas? Here's the bit of code for moving the part, all variables are defined and DistanceLimit is 100.
This is a localscript.
Move = (function (Mouse, Obj)
local BodyPosition, CharTorso = Instance.new("BodyPosition",Obj), Plyr.Character.Torso;
BodyPosition.maxForce = Vector3.new(Obj.Size.X*5000,Obj.Size.Y*5000,Obj.Size.Z*5000)
MovingObject = true
while MovingObject do
local mouseHit = Mouse.Hit.p
--[[CONDITIONAL IS HERE]]--
if (mouseHit - CharTorso.CFrame.p).magnitude <= DistanceLimit then
pos = CFrame.new(mouseHit.X,5,mouseHit.Z)
else
--[[THIS IS WHAT'S MESSED UP]]--
pos = (CFrame.new(mouseHit.X,5,0) + Vector3.new(CharTorso.CFrame * CFrame.new(0,0,DistanceLimit)))
-------------------------------------------
end
BodyPosition.position = (pos).p
wait(0.1)
end
MovingObject = false
BodyPosition:Destroy()
end)

3 comments
I don't fully understand your code and may not be much help, but if the X axis is the problem the try looking into bits where the X axis is mentioned, and I can only suggest printing out messages at each stage, to see if the part does actually go to the set position before it returns to 0
Printing things out wouldn't do me any good. And what you said didn't make any sense. I'm wondering why mouse.Hit.p.X would return 0 when obviously 0 isn't the X axis.. And what I could do to fix it.
Alright, I was just trying to help...