Cooldown for lighter

So my game is a horror game where people rely a lighter to keep their sanity, to prevent people from abuse the lighter (always keep the lighter on, spamming on and off) I want the lighter to have a cooldown system for example: when player activate the lighter, the fire will stay for 30 seconds then it will disappear and player have to wait 60 seconds to activate the lighter again and repeat , when player activate the lighter after using it, it still spark and have the sounds but the fire won’t appear
I have not archive anything so far
Here is he script I use for the lighter


Tool = script.Parent

function onActivated()
if Tool.Fire.Value == false then
Tool.Effects.Fire.Enabled = true
Tool.Effects.Flare.Enabled = true
Tool.Effects.Light.Enabled = true
Spark()
Tool.Fire.Value = true
Tool.Enabled = false
Tool.Effects.On.Playing = true
wait(0.25)
Tool.Enabled = true
else
Tool.Effects.Fire.Enabled = false
Tool.Effects.Flare.Enabled = false
Tool.Effects.Light.Enabled = false
Tool.Fire.Value = false
Tool.Enabled = false
wait(0.25)
Tool.Enabled = true
end
end

function Spark()
Tool.Effects.Sparks.Enabled = true
Tool.Handle.Spark:Play()
wait(0.1)
Tool.Effects.Sparks.Enabled = false
end

function onUnequipped()
Tool.Effects.Fire.Enabled = false
Tool.Effects.Flare.Enabled = false
Tool.Effects.Light.Enabled = false
Tool.Fire.Value = false
end

script.Parent.Activated:connect(onActivated)
script.Parent.Unequipped:connect(onUnequipped)

try putting the Spark() function above the onActivated() function

1 Like

It should work when you put the spark function above onActivated()

1 Like
Tool = script.Parent

function Spark()
Tool.Effects.Sparks.Enabled = true
Tool.Handle.Spark:Play()
wait(0.1)
Tool.Effects.Sparks.Enabled = false
end

function onActivated()
if Tool.Fire.Value == false then
Tool.Effects.Fire.Enabled = true
Tool.Effects.Flare.Enabled = true
Tool.Effects.Light.Enabled = true
Spark()
Tool.Fire.Value = true
Tool.Enabled = false
Tool.Effects.On.Playing = true
wait(0.25)
Tool.Enabled = true
else
Tool.Effects.Fire.Enabled = false
Tool.Effects.Flare.Enabled = false
Tool.Effects.Light.Enabled = false
Tool.Fire.Value = false
Tool.Enabled = false
wait(0.25)
Tool.Enabled = true
end
end

function onUnequipped()
Tool.Effects.Fire.Enabled = false
Tool.Effects.Flare.Enabled = false
Tool.Effects.Light.Enabled = false
Tool.Fire.Value = false
end

script.Parent.Activated:connect(onActivated)
script.Parent.Unequipped:connect(onUnequipped)
1 Like

Thank you for your advise I really appreciate it

The lighter works perfectly fine but it won’t automatically turn off or any cooldown related thing even if I change the wait line