Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Sort of advanced CFrame issues] - How can I fix this?

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

0

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

1

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.

0

Alright, I was just trying to help...

1 answer

--[[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)

1 comment

0

Thank you, but I solved this issue quite a long time ago(:

This discussion is preserved as it was. New answers, comments, and votes are closed.