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

Tycoon sometimes generates too much money. How to fix?

Asked by 5 years ago

Hello, ScriptingHelpers!

Sometimes, my tycoon collector would generate too much money from money bricks.

The thing is that sometimes the amount of generated money (shown on the GUI where players collect money) would jump from 10k, 20k to 1M, which is actually something like 2000000142.

I've been told that debounce could be a fix, but I'm not sure how to add debounce to my script.

SCRIPT WHICH CONVERTS DROPPED BRICKS TO MONEY:

script.Parent.Essentials.Collector.Touched:connect(function(hit)
    if hit:FindFirstChild("Cash") then
        script.Parent.Cash.Value = script.Parent.Cash.Value + hit.Cash.Value
        Instance.new("Sparkles",hit).Color=Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255)
        game.Debris:AddItem(hit,0.1)
    end
end)
0
Have you tried communism? SteamG00B 1633 — 5y
0
Joking asside, where is the script that handles how money is displayed? A debounce will surely make things better, but it might not be the only problem. SteamG00B 1633 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

touched fires insanely without a debounce. It keeps firing so long as the player stays in contact. Debounce is a variable, which is set to true and false when the event fires. The best way to show this is through an example.

local debounce=false--declaring
script.Parent.Essentials.Collector.Touched:Connect(function(hit)
if debounce==false then --checking 
debounce=true--setting true
    if hit:FindFirstChild("Cash") then
        script.Parent.Cash.Value = script.Parent.Cash.Value + hit.Cash.Value
        Instance.new("Sparkles",hit).Color=Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255)
        game.Debris:AddItem(hit,0.1)
    end
wait(3)--change to whatever u want in seconds.
debounce=false--setting to false
end
end)

Oh and also use Connect

0
For some reason this happens after using your code: https://ibb.co/s97Bbtx Supe_RS 0 — 5y
0
thats cuz ur never destroying, and i put it on wait(3). lower the wait and destroy it EmbeddedHorror 299 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I used to have a that problem but after i used this code, it works with out a debounce.

script.Parent.Essentials.Collector.Touched:connect(function(hit)
    if hit:FindFirstChild("Cash") and hit:FindFirstChild("Selling") == nil then
local Tag = Instance.new("BoolValue")
Tag.Name = "Selling"
Tag.Parent = hit
        script.Parent.Cash.Value = script.Parent.Cash.Value + hit.Cash.Value
                Instance.new("Sparkles",hit).Color=Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255)
        game.Debris:AddItem(hit,0.1)
    end
end)

Answer this question