Hi there! I have a collecting item script here that allows me to collect the item every 5 seconds (local waittime) with a debounce involved. However, the debounce seems to be unreliable, as sometimes it waits 5 seconds, other times it will spawn seemingly every .2 seconds. Is there a more reliable method of making this script actually wait 5 seconds every time?
It won't actually be every 5 seconds, it will be more like every 30+ seconds I just set it to 5 for testing purposes. It seems to work with no problems setting it to 20 seconds, but I also can't test it as often set to 20 seconds so maybe I just got lucky - or do debounces work better with higher wait times? I just want to make sure whatever I use, it's reliable and doesn't do anything funky as quickly as I found that glitch.
local CurrencyPickupEvent = game.ReplicatedStorage.CurrencyEvents.CurrencyPickup
local sound = script.Parent:FindFirstChild("Sound") --This is your sound
local waittime = 5 -- Time Between each hit
local amnt = 1 --how much you get for it
local db = false --the debounce
function onTouched(part)
if not db then
db = true --Turn on debounce
local thisplr = game.Players:GetPlayerFromCharacter(part.Parent)
if thisplr then
CurrencyPickupEvent:Fire(thisplr, amnt)
sound:Play(); --Play the sound
end
end
script.Parent.Transparency = 1
wait(waittime)
script.Parent.Transparency = 0
db = false --Turn off debounce
end
script.Parent.Touched:connect(onTouched)
one idea: Should this script just be entirely disabled for x seconds and another script to re enable it after x seconds?
THANK YOU!
