Calling an event with a delay in Roblox Studio. How to do?

24 Views Asked by At

I have a script so that when I touch a cube it takes away its HP

local HP = cube.Healthbar

local function Healtbar() do
    HP.Value = HP.Value - 5
end

cube.Touched:Connect(Healthbar)

But HP is taken away too quickly, literally every frame when I encounter the cube, and I would like to have a small pause after taking damage, after which the damage again passed, but a simple wait() - does not work and information on how to do it I have not found anywhere.

Help please, I'm just learning and I definitely can't do it myself.... please

1

There are 1 best solutions below

0
Winper On

I made it work

local HP = cube.Healthbar
local Cooldown = false
    
local function Healtbar() do
    if Cooldown then return() end
    HP.Value =- 5
    Cooldown = true
    wait(0.5)
    Cooldown = false
end

cube.Touched:Connect(Healthbar)