Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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!

0
Is this from a Udemy lesson? qVoided 221 — 4y
0
no awesomemode14 68 — 4y

1 answer

Log in to vote
1
Answered by
yyyyyy09 246 Moderation Voter
4 years ago
Edited 4 years ago

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.

Ad

Answer this question