Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I create an alternating Kill brick?

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

1 comment

2 answers

✓ Accepted answer

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

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


This discussion is preserved as it was. New answers, comments, and votes are closed.