How would I do this?

So basically I made this weapon that shoots something out. And after a while, it will tween back to its original position. The thing is since it’s a tool, when you move your character the position will be different since it doesn’t just go to the item. Is there any way of achieving this?


why not make it tween back to the characters updated position?

Yeah, but how would you do that?

when the tool is equipped its in the players model, therefore you can reference it from there by doing:

workspace:WaitForChild("Playername"):FindFirstChild("ToolName").Handle.CFrame = workspace:WaitForChild("Playername").HumanoidRootPart.CFRame

or if its a bullet for example you wanna add a value to the bullet, so just instance something like

--Shooting script
local Bullet = OriginalBullet:Clone()
local RecognizingValue ="IntValue")
RecognizingValue.Parent = Bullet
RecognizingValue.Value = player.Name

-- Now you'd just call a module if you want or do something like this
local Module = require(MODULE)
local Seconds = math.random(20) -- After how many seconds you want it to come back
local PlayerWhichShot = RecognizingValue.Value

Module.SendBack(PlayerWhichShot ,Seconds)

Now maybe you’d want to do this in the modulescript:

local mod = {}
function = mod.SendBack(Seconds,Player)
--Now just do the rest here

return mod

Hope this helped

1 Like

I don’t think I explained it that well.

So basically there’s this orb that gets shot out and respawns in the middle of the tool. From there, I want it to tween back to where it first was, but I can’t because it just tweens to the position value of its first position, it doesn’t constantly tween towards it.

Did you make sure that the position you are going to tween is updated?

How would you do that though?

I can send a video of what’s happening if that makes it easier

Sure, you can send a video about your issue.

What I’m saying that right before the tweening, get the position of where you want the orb to go back. I assume what you are doing right now is initially getting the position, which means it couldn’t have been updated when you move your character.

This would probably be something you wouldn’t want to do with TweenService. Once that object is coming back to you, you might be moving around all over the place, and if you just tweened to a certain point, it might be a place the character was before, but has departed from since. There’s two ways I can think of that this could be achieved:

  1. Use a LineForce to attract the object back to the character

  2. On each frame, calculate the difference vector between the object and the character, normalize it, and use delta time between frames to smoothly move the object in the direction of the character

For the second option, the normalized difference vector could be calculated with an expression like this:

(object.Position - character.HumanoidRootPart.Position).Unit

And, if you wanted to achieve an effect similar to the InverseSquareLaw on the LineForce, you could take the reciprocal of the square of the distance between the two positions ((p0 - p1).Magnitude) and use that to scale the movement per frame.

LineForce is a great idea, you’re right. But what if there’s a wall? You would just need to set cancollide to false and anchored??

You might just want to use linear interpolation or lerp. This allows you to smoothly set the percentage on a line, then use delta timing with render stepped to smoothly bring back the line, and because your setting the position manually, there is no collision issues.

1 Like