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

How do I use and add debounce to this script?

I don't understand how to use denounce but I think this would be useful for this script. Can someone explain how to use denounce?

local WaterPouringAudio = script.Parent:WaitForChild("Water Pouring")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("IsADrink") then
		local name = hit.Parent.Name
		WaterPouringAudio.Playing = true
		wait()
		hit.Parent.Name = "Dropping Ice.."
		wait(2.4)
		hit.Parent.Name = "Iced " .. name
		hit.Parent.Ice.Transparency = 0.4
	end
end)

1 comment

0

It keeps auto-correcting debounce to denounce. Sorry about that.

1 answer

✓ Accepted answer

First you have to define a boolean value. Then you have to add a check to see if the value is what it should to make it work. Then you just turn the value to the opposite. Then turn the value back after you're done what you needed to do.

Maybe that sounds confusing, but when it's in code it will make more sense

local WaterPouringAudio = script.Parent:WaitForChild("Water Pouring")

local debounce = false -- define debounce

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("IsADrink") and not debounce then -- check if debounce = false
	debounce = true -- change it to true so it goes through only once
        local name = hit.Parent.Name
        WaterPouringAudio.Playing = true
        wait()
        hit.Parent.Name = "Dropping Ice.."
        wait(2.4)
        hit.Parent.Name = "Iced " .. name
        hit.Parent.Ice.Transparency = 0.4
	debounce = false -- change it back so it can function again
    end
end)

Hope I helped, if you have any questions please let me know!

1 comment

0

Thank you so much!

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