I'm quite new to Lua, and I've made a script that heals the player when they step on a block. The healing works but when I try to add a cooldown to it, it doesn't work. This is the script:
local brick = script.Parent
local cd = false
function onTouched(hit)
while cd = false do
local cd = true
brick.BrickColor = BrickColor.Red()
local hpRestored = 100 - hit.Parent.Humanoid.Health
for i = 1, hpRestored do
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health + 1
wait(0.03)
end
wait(8)
brick.BrickColor = BrickColor.Green()
local cd = false
end
end
script.Parent.Touched:connect(onTouched)
Thanks :)

2 comments
Great! Thanks :)
No problem, I like how duckwit edited his answer after noticing that I wasn't using local before the variable.