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

How do I create an alternating Kill brick?

Asked by 6 years ago
while true do
    script.Parent.BrickColor = BrickColor.new(255,0,0)
    --KILL PLAYER FUNCTION--
    wait(math.random(3,7))
    script.Parent.BrickColor = BrickColor.new(255,255,255)
    wait(math.random(3,7))
end

Ive tried Disabling and Enabling a kill script(which didn't work). Ive also tried to put a function above the while true do loop that kills the player(didn't work again)

This didnt work:

function Kill(part)--probably has to do with parameter
    local hum = part.Parent:FindFirstChild("Humanoid")
    if hum ~= nil then
        hum.Health = 0
    end
end

script.Parent.Touched:Connect(Kill)

while true do
    script.Parent.BrickColor = BrickColor.new(255,0,0)
    Kill()
    wait(math.random(3,7))
    script.Parent.BrickColor = BrickColor.new(255,255,255)
    wait(math.random(3,7))
end

Can anybody help with this simple question

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Paste this script in a script in the part.

local killing = false
script.Parent.Touched:connect(function(hit)
    if killing then
    hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 1
    end
end)

while true do
    script.Parent.BrickColor = BrickColor.new(255,0,0)
    killing = true
    wait(math.random(3,7))
    script.Parent.BrickColor = BrickColor.new(255,255,255)
    killing = false
    wait(math.random(3,7))
end

This kills when it's red doesn't kill when it's white

Ad
Log in to vote
1
Answered by 6 years ago

Use this because you are not supplying a parameter at line 12 just check in the if statement if you are meant to kill the player use this.

killing = true -- Should the part kill
function Kill(part)--probably has to do with parameter
       local hum = part.Parent:FindFirstChild("Humanoid")
        if hum ~= nil and killing == true then
            hum.Health = 0
        end
    end

    script.Parent.Touched:Connect(Kill)

    while true do
        script.Parent.BrickColor = BrickColor.new(255,0,0)
        killing = true
        wait(math.random(3,7))
        script.Parent.BrickColor = BrickColor.new(255,255,255)
    killing = false
wait(math.random(3,7))
end


Answer this question