The tween isnt tweening

I have a script that is supposed to Tween items to the player.

local TS = game:GetService("TweenService")
local function pickUpItem(v)
	repeat wait(0) until (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - v.Position).Magnitude < 6
	v.Anchored = true
	v.CanCollide = false
	local info = TweenInfo.new(0.15)
	local newPos = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
	local tween = TS:Create(v, info, {Position = newPos})
	tween:Play()
	tween.Completed:Wait()
	local player = game.Players:GetPlayerFromCharacter(script.Parent)
	v.Parent = player.Backpack
	v.BackpackRustle:Play()
end

workspace.Drops.ChildAdded:Connect(function()
	for i, v in pairs(workspace.Drops:GetChildren()) do
		task.spawn(function()
			pickUpItem(v)
		end)
	end
end)

Sometimes the Tween works, but at other times it just skips to the collecting part. What is going on? I’ve tried some things, but nothing works.

1 Like

There’s suppose to be more variables in local info = TweenInfo.new(0.15)

So replace that with the code below

local info = TweenInfo.new(0.15,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)
1 Like

There doesn’t have to be. It works perfectly fine, just… only sometimes.

Oh, didn’t know that.

Though try cleaning up your code, it might do something.

Your script is looping over every part when a new one is added when it should only get the new part that was added. This is most likely overlapping the functions.

Code:

local TS = game:GetService("TweenService")
local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer

local info = TweenInfo.new(0.15)

local function pickUpItem(v)
	repeat task.wait() until (LocalPlayer.Character.PrimaryPart.Position - v.Position).Magnitude < 6
	
	v.Anchored = true
	v.CanCollide = false
	
	local newPos = LocalPlayer.Character.HumanoidRootPart.Position
	
	local tween = TS:Create(v, info, {Position = newPos})
	tween:Play()
	tween.Completed:Wait()
	
	v.Parent = LocalPlayer.Backpack
	v.BackpackRustle:Play()
end

workspace.Drops.ChildAdded:Connect(pickUpItem)
for i, v in pairs(workspace.Drops:GetChildren()) do
	task.spawn(pickUpItem, v)
end

Also, your code will not replicate to the server, because you’re doing this on a LocalScript. I’m not sure if that’s intended or not.

Now they’re all tweening, but parts with Welded parts/meshparts inside have a problem. The main part tweens, but the parts/meshpart inside doesn’t. Is there any way to get rid of this error?
Edit: I’ma try smth rq
Edit 2: it worked. sick. Thanks for the help!

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