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

How can you make one object pull towards another object?

I want to make a script where when the player clicks on an unanchored object, the object flies towards the box that the player is holding. So I did this in a localscript

local plr = game.Players.LocalPlayer
local active = false
script.Parent.Equipped:connect(function(Mouse) --the parent of script.Parent is the tool
active = true
script.Parent.Mouse.Button1Clicked:connect(function()
if active==true and part.ClassName=='Part' then --part is supposed to be the thing that gets grabbed, but I havent made it into a working variable, which idk how
print('grab')
grabForce = instance.new('BodyForce')
grabForce.Force = Vector3.new('1,0,0') * 100
grabForce.Parent = part

end
end)
end)

script.Parent.Unequipped:connect(function()
active = false
end)

I havent figured it out yet, Idk if I am doing it right

1 answer

✓ Accepted answer

If you don't want it to be instant, I'd use lerp to move it smoothly. Lerp, short for linear interpolation, is a mathematical technique for producing intermediate states between a start and an endpoint. It is related to GUI Animations.

More about lerp: https://www.robloxdev.com/articles/Lerp

I hope this helped.

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