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 7 years ago
1while true do
2    script.Parent.BrickColor = BrickColor.new(255,0,0)
3    --KILL PLAYER FUNCTION--
4    wait(math.random(3,7))
5    script.Parent.BrickColor = BrickColor.new(255,255,255)
6    wait(math.random(3,7))
7end

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:

01function Kill(part)--probably has to do with parameter
02    local hum = part.Parent:FindFirstChild("Humanoid")
03    if hum ~= nil then
04        hum.Health = 0
05    end
06end
07 
08script.Parent.Touched:Connect(Kill)
09 
10while true do
11    script.Parent.BrickColor = BrickColor.new(255,0,0)
12    Kill()
13    wait(math.random(3,7))
14    script.Parent.BrickColor = BrickColor.new(255,255,255)
15    wait(math.random(3,7))
16end

Can anybody help with this simple question

2 answers

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

Paste this script in a script in the part.

01local killing = false
02script.Parent.Touched:connect(function(hit)
03    if killing then
04    hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 1
05    end
06end)
07 
08while true do
09    script.Parent.BrickColor = BrickColor.new(255,0,0)
10    killing = true
11    wait(math.random(3,7))
12    script.Parent.BrickColor = BrickColor.new(255,255,255)
13    killing = false
14    wait(math.random(3,7))
15end

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

Ad
Log in to vote
1
Answered by 7 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.

01killing = true -- Should the part kill
02function Kill(part)--probably has to do with parameter
03       local hum = part.Parent:FindFirstChild("Humanoid")
04        if hum ~= nil and killing == true then
05            hum.Health = 0
06        end
07    end
08 
09    script.Parent.Touched:Connect(Kill)
10 
11    while true do
12        script.Parent.BrickColor = BrickColor.new(255,0,0)
13        killing = true
14        wait(math.random(3,7))
15        script.Parent.BrickColor = BrickColor.new(255,255,255)
16    killing = false
17wait(math.random(3,7))
18end

Answer this question