local KillBrick = workspace.KillBrick
KillBrick.Touched:Connect(function(touched)
local humanoid = touched.Parent:FindFirstChild(“Humanoid”)
if humanoid then
humanoid.Health = 0
end
end)
local DamageKillBrick = workspace.KillBrick
DamageKillBrick.Touched:Connect(function(touching)
local humanoid = touching.Parent:FindFirstChild(“Humanoid”)
if humanoid then
humanoid.Health = 0.5
end
end)
local DamageKillBrick = workspace.DamageKillBrick -- you need to reference the correct part
DamageKillBrick.Touched:Connect(function(touching)
local humanoid = touching.Parent:FindFirstChild(“Humanoid”)
if humanoid then
humanoid.Health -= 5
end
end)
You referenced the DamageKillBrick variable as workspace.KillBrick.
I’d like to inform you of a more performant way to create a kill/damage part. You can use CollectionService to bind the same code to a multitude of parts. Additionally you can look up a tutorial to comprehend the service.
Side stuff
Here’s some optimized code which contains some additional variables for configuration:
-- services
local players = game:GetService("Players")
-- variables
local damageKillBrick = workspace:WaitForChild("DamageBrick")
local debounces = {}
local COOLDOWN_LENGTH = 0.75
local DAMAGE = 20
-- functions
damageKillBrick.Touched:Connect(
function (otherPart)
local player = players:GetPlayerFromCharacter(otherPart.Parent)
if (not player) then return end
if (table.find(debounces, player.UserId)) then return end
table.insert(debounces, player.UserId)
local character = otherPart.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.Health -= DAMAGE
task.delay(COOLDOWN_LENGTH,
function ()
table.remove(debounces, table.find(debounces, player.UserId))
end
)
end
)
You can mark my reply as the solution if I’ve solved your problem, good luck