Magnetizing a collectable towards the player?

Hi there,
I’m trying to make code that would magnetize a collectable towards the player once it touches the magnet’s hitbox. It seems easy enough, but I can’t figure out a way to get the collectable to cleanly glide towards the player, as the player would be constantly moving.
At first, I tried using tweens, but even with very fast tweens, it didn’t work well, since tweens can’t really constantly update the position it’s tweening to.
Here’s a snippet of the relevant code:

---On touch...
function onTouched(part)
	if part.Name == "MagnetHitbox" and debounce == false then
		debounce = true
		local magTween = TweenService:Create(script.Parent, tweenInfo2 {Position = part.Parent.Position})
		magTween:Play()
		wait(0.3) --Waits until the tween ends
---Collect
		local userName = part:FindFirstChild("User").Value --The "User" StringValue inside the magnet hitbox
		local theuser = game.Players:FindFirstChild(userName)
		local thescore = theuser:FindFirstChild("Bells") --"Bells" are the collectable
		Collect(theuser, thescore)
		debounce = false
	end
end

script.Parent.Touched:connect(onTouched)

Next, I found out about LineForce. It was almost what I wanted, but I couldn’t find a way to only apply force to the collectable, so both the player and the collectable flung into each other.

Is there any other way I could go about doing this? Any help is greatly appreciated.

1 Like

VectorForce is what you’re looking for

Sorry for what may be an obvious answer, but how would I use VectorForce to do it? I looked into it, and it seems like VectorForce applies a constant force relative to the local space of a certain attachment, and you have to specify the direction yourself. How would I calculate the direction and force it needs to travel to the player? Especially when they’re moving?

Attachment 0 should be the collectable and attachment1 is the player. Moreover this bool value should be false to avoid force being applied on attachment1.

Oh wow. Thank you, I can’t believe I missed that.