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

Script Upgrades Part Many Times?

Hey, I Was Making A Just Making A Tycoon And When I Tested It The Upgrader Just Upgrades The Part Multiple Times Which Caused Me To Get Cash Really Fast, I Tried To Fix It But I Can't So Can Anyone Help me Please Sorry If You Cant Understand :

script.Parent.Upgrade.Touched:connect(function(hit)
	if hit:FindFirstChild("Cash") then
		hit.Cash.Value = hit.Cash.Value * 2
		hit.Reflectance = hit.Reflectance + 0.1 
	end
end)

1 answer

✓ Accepted answer

Hello.

Because of how the engine works, the script will detect the character stepping on it multiple times, it is for that reason that we use Debounce to stop from that happening, you can learn more about debounce here: https://developer.roblox.com/en-us/articles/Debounce

It's quite simple to add a debounce script, and here is how you would do it for a script like yours:

local Debounce = false

script.Parent.Upgrade.Touched:Connect(function(hit)
    if hit:FindFirstChild("Cash") then
     if not Debounce then 
      Debounce = true
        hit.Cash.Value = hit.Cash.Value * 2
         wait(0.1)
        hit.Reflectance = hit.Reflectance + 0.1 
       Debounce = false
     end
    end
end)

Hopefully this worked! If so, feel free to accept my answer, or, if you have any questions, leave them in the comments below!

1 comment

0

connect is deprecated. Use Connect instead.

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