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

Tycoon sometimes generates too much money. How to fix?

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)

2 comments

0

Have you tried communism?

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.

2 answers

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

2 comments

0

For some reason this happens after using your code: https://ibb.co/s97Bbtx

0

thats cuz ur never destroying, and i put it on wait(3). lower the wait and destroy it

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)

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