Part floats towars player

I can’t find a good way to make the tween work for this, so instead just change the CFrame, probably not the best way to do it but it’s a temporary fix

local runService = game:GetService(“RunService”)

game.Players.PlayerAdded:Connect(function(player) 
   task.wait(5) 
   local character = player.Character or  player.CharacterAdded:Wait() 
 
   local part = script.Parent 
   local tweenService =   game:GetService("TweenService") 
   local tweenToPositon =  character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2) 
   local tween = tweenService:Create(part,TweenInfo.new(5), {CFrame = tweenToPositon}) 
 
   tween:Play()
   tween:Completed:Wait()
   runService.Stepped:Connect(function()
      if (part.Position - character.HumanoidRootPart.Position).Magnitude < 9 then
         part.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2)
      end
   end)
end)

few errors i have found in the script

Sorry put the colon again make it (.), change the quotation on runService your self, idk why it did that

I don’t want it to go towards me when its very far away, i only want it to go towards be when i am close to it

That is what it’s doing it’s following when less than 9 studs

That’s a lot of messages. Why are you using tweenservice for this? How about using physics?

These require not much scripting, all you need is to set their attachments to the player and the part you want to move.

You mean attaching it to the character?, also I only tween it once

for some reason its going toward me when it is very far away

Ok do this then

local runService = game:GetService(“RunService”)

game.Players.PlayerAdded:Connect(function(player) 
   task.wait(5) 
   local character = player.Character or  player.CharacterAdded:Wait() 
 
   local part = script.Parent 
   
   runService.Stepped:Connect(function()
      if (part.Position - character.HumanoidRootPart.Position).Magnitude < 9 then
         part.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2)
      end
   end)
end)
2 Likes

IT works! thanks a bunch this help me out a lot

1 Like

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