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