Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do You Make a Brick Kill You Over Time?

Asked by 6 years ago

I am making a game where if you stand on a convener (that's supposed to be water) you keep taking damage until you step onto another block. I've tried a bunch of different codes and none of them have seemed to work correctly. Does anyone have ideas?

2 answers

Log in to vote
0
Answered by 6 years ago

you could make a script like this if you put it inside of the water

local Touching = false
local TouchedBy = nil
local Debounce = false

script.Parent.Touched:connect(function(t)
Touching = true
if t.Parent:FindFirstChild("Humanoid") ~= nil then
TouchedBy = t.Parent
end
end

script.Parent.TouchEnded:connect(function()
Touching = false
end

while wait() do
if Touching == true and TouchedBy ~= nil and Debounce == false then
    Debounce = true
    TouchedBy.Humanoid.Health = TouchedBy.Humanoid.Health - 10 -- the amount of damage you want it to deal
    wait(1) -- the time you want it to wait before dam damaging again
    Debounce = false
end
end


Ad
Log in to vote
-2
Answered by
hellmatic 1523 Moderation Voter
6 years ago
local Damage = 5
local Seconds = 1 -- so every 1 second, it damages the player by 5

script.Parent.Touched:connect(function(hit)
    if hit and hit.Parent:FindFirstChild('Humanoid') then 
        local humanoid = hit.Parent:FindFirstChild('Humanoid')
        humanoid:TakeDamage(Damage)
        wait(Seconds)
    end
end)

Answer this question