✓ Accepted answer
First of all add debounce so that the player who touches the brick doesn't lose all their lives when only touching once.
local db = false
function onTouched(hit)
if db == false then
db = true
local hitname = tostring(hit.Parent)
if game.Players:findFirstChild(hitname) then
local player = game.Players:findFirstChild(hitname)
local lives = player:findFirstChild("Lives")
lives.Value = lives.Value - 1
end
wait(1)
db = false
end
end
script.Parent.Touched:connect(onTouched)
Next we want to kill the player when the player has lost all their lives so we add this:
local db = false
function onTouched(hit)
if db == false then
db = true
local hitname = tostring(hit.Parent)
if game.Players:findFirstChild(hitname) then
local player = game.Players:findFirstChild(hitname)
local lives = player:findFirstChild("Lives")
lives.Value = lives.Value - 1
if lives.Value <= 0 then
hit.Parent.Humanoid.Health = 0
end
end
wait(1)
db = false
end
end
script.Parent.Touched:connect(onTouched)