Problematic Coin Collection System

I am trying to create a Coin collection system but it keeps being buggy. So far, when a player destroys a part, coins being a cube with some values inside of it are put into a folder in the workspace and spread out into the actual world. When the player is close enough to the coin, it will tween to the player and give the player some cash.
(Also, I am using big numbers in my game shown by Bignum and Abbr which just simplifies things)

My problem is that I put out 10 coins into the world, each one being about 100 billion cash, but when I pick everything up I never have ended up with 1 trillion cash added on.

So far, I have tried to use tables to sort things out and the Collection service to label things differently but I just can’t figure it out

This is my code to collect the parts:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local BigNum = require(game.ReplicatedStorage.ModuleScripts.ModuleScript)
local Abbr = require(game.ReplicatedStorage.ModuleScripts.Abbreviate)

local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")

while true do
	for i, drop in pairs(workspace.Drops:GetChildren()) do
		
		if drop:IsA("Part") and drop:FindFirstChild("PickupValue") then

			local mag = (root.Position - drop.Position).Magnitude
			if mag <= 6 then
				
				local value = drop.PickupValue.Value --This value is around 100 billion
				local currencyName = drop.CurrencyName.Value
				local Tween = ts:Create(drop, TweenInfo.new(mag*0.01, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Position = root.Position})
				Tween:Play()
				Tween.Completed:Connect(function()
					local newvalue = BigNum.__tostring(BigNum.new(plr.Stats:FindFirstChild(currencyName).Value) + BigNum.new(Abbr.LengthenPoints(value)))
					rs.Events:WaitForChild("ChangeValue"):FireServer(plr.Stats:FindFirstChild(currencyName), newvalue) --changes the value in the stats
					drop:Destroy()
				end)
			end
		end
		wait(0.01)
	end
	wait(0.01)
end
2 Likes