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)
--[[If I understand correctly, you're trying to send something to your mouse position?
Try this.. --]]
local player=game.Players.LocalPlayer local mouse=player:GetMouse() local torso = player.Character.Torso torso.CFrame = CFrame.new(mouse.Hit.p) + Vector3.new(0,3,0)
Closed as Not Constructive by Goulstem
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?