How do I make the orb pickup look better? It doesnt really tween into my character because I move.
orb.Touched:Connect(function(hit)
if hit.Name == "PickupHitbox" then
local player = Players:GetPlayerByUserId(hit.ownerId.Value)
if not player then return end
local character = player.Character
if not character then return end
local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local goal = {}
goal.Position = character:WaitForChild("HumanoidRootPart").Position
goal.Size = Vector3.new(0, 0, 0)
goal.Transparency = 1
local orbTween = TweenService:Create(orb, tweenInfo, goal)
orbTween:Play()
wait(0.1)
orb:Destroy()
end
end)
One way that might make it look better is basing the speed the move to the player off of the distance to the player, rather than it just being when you are close enough
The reason for this is because the touched event triggers once it enters the region and not while it stays inside it, therefore never playing the updated tween. What if your touched event only lets the script know that a character was found, and then you have a loop constantly playing a tween going towards the player (if found) that then destroys the orb once it’s in a certain range? Here’s the updated code:
local orb = script.Parent
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local foundCharacter = nil
local startTime = nil
orb.Touched:Connect(function(hit)
if hit.Name == "PickupHitbox" then
local player = Players:GetPlayerByUserId(hit.ownerId.Value)
if not player then return end
local character = player.Character
if not character then return end
if not foundCharacter then foundCharacter = character end
end
end)
--the wait is up to you, maybe could be just task.wait()
while wait(0.05) do
if not foundCharacter then continue end
--how close it has to be to be destroyed
local distanceThreshold = 0.5
if not startTime then startTime = tick() end
--if the distance is small enough, or if the start time is more than 1 second ago, destroy the orb
if(math.abs(orb.Position.Magnitude - foundCharacter.HumanoidRootPart.Position.Magnitude) < distanceThreshold) or (startTime < tick() - 1) then orb:Destroy() end
local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local goal = {}
goal.Position = foundCharacter:WaitForChild("HumanoidRootPart").Position
goal.Size = Vector3.new(0, 0, 0)
goal.Transparency = 1
local orbTween = TweenService:Create(orb, tweenInfo, goal)
orbTween:Play()
end
I also added a time threshold since I’m not sure how fast a player will be able to go in your game and it prevents an orb from following forever. It can be removed if you want, just delete the or statement and remove the startTime variable.