Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my collectors sometimes collect twice more than the original value?

My cash collects automatically collect cash and put the value on the leaderboard. But sometimes the collecters randomly collects twice as more than the original value of the dropper cube, for example, the collectors collect $4 instead of $2.

Here is the code:

local Money = script.Parent.Amount
local Debris = game:GetService('Debris')

for i,v in pairs(script.Parent.Parent:GetChildren()) do
	if v.Name == "CollectorPart" then
		v.Touched:connect(function(Part)
			if Part:FindFirstChild('Cash') then
				Money.Value = Money.Value + Part.Cash.Value
				Debris:AddItem(Part,0.2)
				--print(Money.Value)
			end
		end)
	end
end

The Money is an int value where every 0.11 sec it sets to zero; here is the code:

while true do 
	wait(0.11)
	script.Parent.Value = 0
end

Thanks for the Help!

2 comments

0

Is this from a Udemy lesson?

0

no

1 answer

✓ Accepted answer

That's because within the 0.2 second time frame where you add the money to debris service, the player can touch the money part twice making it give you $4, instead of debris service use Part:Destroy(). You don't need the money to stay there for 0.2 seconds.

This discussion is preserved as it was. New answers, comments, and votes are closed.