Part floats towars player

Is there a way to have a part float toward the player? I’m making a quest for a game where you need to collect something and i want it to float towards the player

3 Likes
local part = (where the part is)
local tweenService = game:GetService("TweenService")
local tweenToPosition = character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)

local tween = tweenService:Create(part, (the info you want), {Position = tweenToPosition)

tween:Play()

I don’t understand the “the info you want” part not to mention whenever i put the script in and add the part position a bunch of errors appear in the script

You can do

local tween = tweenService:Create(part, (TweenInfo.new(5)), {Position = tweenToPosition)

The 5 can be any number(it’s the amount of time that it takes to get to tweenToPosition)

the part area is not right apparently
image is it the position?

No the part is the actual part object, where you want to put the position for the part to go is the tweenToPosition variable

is it a local script cause there is no other way to find the character, also, where does the script go?

Oh also instead of a position value I already made it so it go’s in front of the character you just need to make the character variable in your script

When do you want it to float then?

If i have it as a local script and put it in the part it does not work

local character = game.Players.LocalPlayer.Character
local part = script.Parent
local tweenService = game:GetService("TweenService")
local tweenToPosition = character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)

local tween = tweenService:Create(part, (TweenInfo.new(5)), {Position = tweenToPosition)

tween:Play()

You can’t put a local script in the workspace and you don’t need a local script, make it a server script then do

game.Players.PlayerAdded:Connect(function(player))
   local character = player.Character or player:CharacterAdded:Wait()
   
   local part = script.Parent
   local tweenService = game:GetService("TweenService")
   local tweenToPosition = character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)

   local tween = tweenService:Create(part, (TweenInfo.new(5)), {Position = tweenToPosition)

   tween:Play()
end

there is an error when i paste it

Oh sorry this

game.Players.PlayerAdded:Connect(function(player)
   local character = player.Character or player:CharacterAdded:Wait()
   
   local part = script.Parent
   local tweenService = game:GetService("TweenService")
   local tweenToPosition = character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)

   local tween = tweenService:Create(part, (TweenInfo.new(5)), {Position = tweenToPosition})

   tween:Play()
end)

Oh change position to CFrame I forgot

the only error is this
image

which position? Because there are multiple

Oh it’s a silly mistake it’s not a colon before CharacterAdded it’s(.)

its not working even though there are no errors

Is it not moving or already moved?

its not moving its just staying in place