Trying To Make Part To Keep Moving To its Goal until its reached

Im trying to make a orb effect where it tweens to the player but i dont know how to make it where it keeps following the players humanoid root part untill it touches the rootpart

this is the function i have in a module

function module.SpawnOrb(SpawnPosition : Vector3,PartToTouch : Part)
	local Info = TweenInfo.new(.65,Enum.EasingStyle.Back,Enum.EasingDirection.In,0,false,0)
	local Info2 = TweenInfo.new(.25,Enum.EasingStyle.Exponential,Enum.EasingDirection.In,0,false,0)
	
	
	local Orb = game.ReplicatedStorage.FX.MoneyOrb:Clone()
	Orb.Parent = game.Workspace
	
	Orb.Transparency = 1
	local FadeTween = TweenService:Create(Orb,Info2,{Transparency = 0})
	Orb.Position = SpawnPosition
	FadeTween:Play()
	
	FadeTween.Completed:Connect(function()
			local MoveTween = TweenService:Create(Orb,Info,{CFrame = PartToTouch.CFrame})
			MoveTween:Play()

			MoveTween.Completed:Connect(function()
				
				local FadeOutTween = TweenService:Create(Orb,Info2,{Transparency = 1})
				FadeOutTween:Play()
				
				wait(1)
				Orb:Destroy()
			end)
		
	end)
	
end
RandomModules.SpawnOrb(script.Parent.Parent.Parent.GlassBall.Position,Player.Character:WaitForChild("HumanoidRootPart"))

this is the code that fires it

if memory serves you could accomplish this by using something along the lines of

local Connection

task.delay(5, function() -- you can replace 5 with a time limit of your choosing
  Connection:Disconnect()
  Connection = nil
end)

Connection = game:GetService("RunService").Heartbeat:Connect(function()
  MoveTween.Completed:Connect(function()
   MoveTween:Destroy()
   if Orb.CFrame == PartToTouch.CFrame then
     if Connection ~= nil then
       Connection:Disconnect()
       Connection = nil
  end)
  MoveTween:Play()
end)

im not entirely sure if this would work as intended or not however it should provide you with a good idea as to how the concept could work

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.