Try to make telekinesis power

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hi, I would like to be able to lift other players or parts not anchored in the air like a telekinesis power
  2. What is the issue? Include screenshots / videos if possible!
    I tried to follow this tutorial Dragging objects with the mouse
    but the part bounce all the time
    2022-07-21 13-46-46
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried to reproduce this tutorial Dragging objects with the mouse

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

In a local script

mouse.Button1Down:connect(function() 
	if mouse.Target ~= nil and mouse.Target.Locked == false then		
		if mouse.Target.Anchored == false then
			if mouse.Target:FindFirstChild("CanBeDragged") then
				target = mouse.Target
				mouse.TargetFilter = target
				SetNetworkOwner:FireServer(target)
				down = true  
			end
		end
	end 
end)

mouse.Move:Connect(function()
	if down == true and target ~= nil then 
		target.Position = Character.Head.Position + (mouse.Hit.Position - Character.Head.Position).Unit * 20
	end 
end) 

mouse.Button1Up:connect(function()
	down = false
	mouse.TargetFilter = nil
	target = nil
end)

In a server script

local SetNetworkOwner = game.ReplicatedStorage.SetNetworkOwner

SetNetworkOwner.OnServerEvent:Connect(function(client, part)
	part:SetNetworkOwner(client)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

use body positions

code:

local BodyPosition    = Instance.new("BodyPosition")
BodyPosition.MaxForce = Vector3.new(12000, 12000, 12000)
BodyPosition.P        = BodyPosition.P
BodyPosition.D        = 550

local mouse = game.Players.LocalPlayer:GetMouse()

local SetNetworkOwner = game.ReplicatedStorage.SetNetworkOwner

local Character = game.Players.LocalPlayer.Character

local RunService = game:GetService("RunService")

mouse.Button1Down:connect(function() 
	if mouse.Target ~= nil and mouse.Target.Locked == false then		
		if mouse.Target.Anchored == false then
			if mouse.Target:FindFirstChild("CanBeDragged") then
				target = mouse.Target
				mouse.TargetFilter = target
				SetNetworkOwner:FireServer(target)
				down = true  
			end
		end
	end 
end)

local stepped

mouse.Move:Connect(function()
	if down == true and target ~= nil then 
		BodyPosition.Parent = target
		stepped = RunService.Heartbeat:Connect(function()
			BodyPosition.Position = Character.Head.Position + (mouse.Hit.Position - Character.Head.Position).Unit * 20
		end)
	end 
end) 

mouse.Button1Up:connect(function()
	down = false
	mouse.TargetFilter = nil
	
	if stepped then
		stepped:Disconnect()
	end
	BodyPosition.Parent = nil
	
	target = nil
end)

hope this works and dont forget to hit the solution if this works thank you

2 Likes