Pickup Item Function Not Working

I have this, it’s a script that when the player gets close to an item it gets picked up… but it just… doesn’t work.
Script location - game.StarterPlayer.StarterCharacterScripts.LocalScript

local TS = game:GetService("TweenService")
local function pickUpItem(v)
	local Mag = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - v.Position).Magnitude
	repeat wait(0) until Mag < 6
	v.Anchored = true
	v.CanCollide = false
	local info = TweenInfo.new(0.3)
	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
		pickUpItem(v)
	end
end)

youre saving the magnitude to the variable only once so it doesnt update when the player moves,

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.3)
	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
		pickUpItem(v)
	end
end)

you cant pick up multiple at the same time for some reason and i think its because of the “wait” thing, is there any way to avoid this?

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.3)
	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)

this works, but theres a bug where if one is being tweened another doesn’t. its either that or sometimes they just dont play. i guess i’ll just figure that out and i’ll be good
edit: i literally cant figure it out

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