I am trying to make a water drink script, it works but doenst respect the cooldown. how i can fix it?
https://pastebin.com/79L0qXsk
So you need to use debounce
CD.MouseClick:Connect(function(player) local healAmount = 15 local canDrink = true local cooldown = 0.8 local h = player.Character.Humanoid local currentHealth = h.Health local newHealth = currentHealth + 15 local gui = player.PlayerGui.Interaction.Int local db = false if h and canDrink == true and not db then if h.Health > 0 and h.Health < h.MaxHealth then canDrink = false local currentHealth = h.Health local newHealth = currentHealth + healAmount h.Health = newHealth db = true wait(0.8) canDrink = true db = false end end end)
It should work but haven't tested
That probably wont even work. I would put all the local values outside of the function except the ones that refer to the parameter as so:
local healAmount = 15 local canDrink = true local cooldown = 0.8 CD.MouseClick:Connect(function(player) local h = player.Character.Humanoid local currentHealth = h.Health local newHealth = currentHealth + healthAmount local gui = player.PlayerGui.Interaction.Int if h and canDrink == true then if h.Health > 0 and h.Health < h.MaxHealth then canDrink = false local currentHealth = h.Health local newHealth = currentHealth + healAmount h.Health = newHealth wait(cooldown) canDrink = true end end end)
It wouldnt "respect the cooldown" because everytime you would click it, it would be true because when you clicked it, it would set it to true right away.