BodyPosition help

I am making a telekinesis script and I want the object to hover next to the player’s right hand, but when I move my character to face certain directions, it makes the object go in other positions, like inside my head or the other side of my body.

this is my script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("Telekinesis2")

local TK = {}

Event.OnServerEvent:Connect(function(player, State, Object, Mouse, mousePosition)
	if State == "Begin" and player:FindFirstChild("Telekinesis") then
		print("begin")
		
		local Humanoid = Object.Parent:FindFirstChild("Humanoid") or Object.Parent.Parent:FindFirstChild("Humanoid")
		player.Character.Humanoid.WalkSpeed = 8
		
		TK[Object] = true
		
		local Model = nil
		if Object.Parent:IsA("Model") then
			Model = Object.Parent
		elseif Object.Parent.Parent:IsA("Model") then
			Model = Object.Parent.Parent
		end
		local Massless = {}
		table.insert(Massless, Object)
		local Character = nil
		if Humanoid then
			Character = Humanoid.Parent
		end
		
		local deathConnection = player.Character.Humanoid.Died:Connect(function()
			TK[Object] = false
		end)
		
		if Model then
			for _,v in next, Model:GetDescendants() do
				if v:IsA("BasePart") and v ~= Object and not v.Massless then
					table.insert(Massless, v)
				end
				if v.Name == "objTele" then
					return
				end
			end
		end
		for _,v in next, Massless do
			v.Massless = true
		end
		
		local BP = Instance.new("BodyPosition")
		BP.Position = Vector3.new(player.Character.RightHand.CFrame.X, player.Character.RightHand.CFrame.Y, player.Character.RightHand.CFrame.Z) + Vector3.new(2, 1.5, 0)
		BP.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		BP.Name = "TK"
		BP.Parent = Object
		
		while player and BP and TK[Object] do
			wait()
			BP.Position = Vector3.new(player.Character.RightHand.CFrame.X, player.Character.RightHand.CFrame.Y, player.Character.RightHand.CFrame.Z) + Vector3.new(2, 1.5, 0)
		end
	
	elseif State == "Finish" then
		TK[Object] = false
		local BP = Object:FindFirstChild("TK")
		BP:Destroy()
		player.Character.Humanoid.WalkSpeed = 16
	end
end)

note: I have tried a weld constraint and it just flung me around

bumping this, i still havent found a fix

Maybe play around with orientaton? I’m a little confused of what the problem is.

the knife that i’m making float is supposed to stay next to my right hand, like it is in the start of the video

when i move my character to face a different way, the knife changes positions and goes inside my head instead of next to my hand

yeah that’s happening due to this line:

BP.Position = Vector3.new(player.Character.RightHand.CFrame.X, ...) + Vector3.new(2, 1.5, 0)

The knife will always be 2 studs to the positive x from the hand’s position in world. It isn’t neccesarily 2 studs to the right side of the hand.

is there any way to make it always 2 studs to the right side?

give motor6d a shot:

1 Like

it just attaches it to my hand and makes me float
image

are you using c0? that might help with offset.

1 Like

it offset it but it’s stiff and still making me float, its not following me smoothy like it should anymore
image

could you try this code:
Object.Massless = true
Object.Anchored = false
Object.CanCollide = false

local weld = Instance.new("Motor6D")
weld.Part0 = character.HumanoidRootPart
weld.Part1 = Object
weld.Parent = Object
weld.C0 = CFrame.new(2,0,0)

the issue of floating stems from massless being false

1 Like

tho using motors does take away from the smoothness if you wish to achieve that, in that case you need more precise BP calculations

i’m still floating and it’s still stiff
image

Adding a vector wont adjust for rotation
Instead multiply a CFrame and then get the position of it as such:
BP.Position = (player.Character.RightHand.CFrame * CFrame.new(2, 1.5, 0)).Position

1 Like

are you trying to achieve a smooth follow or a fixed state?

i want it to follow me smoothly, like it does in the video, but just always float above the right hand

possibly take a look at alienorientation as well and play around with that.

1 Like

it now floats behind me
image

Play around with the offset. if its always behind you that means the code works correctly

1 Like

it worked! thank you so much :heart:

1 Like