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

How do i make a killbrick that goes off randomly?

so i want to make an obstacle where a player has to travel across two parts but in between i want a killbrick that goes of repeatedly after waiting a certain amount of time

this is the script i have rn but im not sure what to do anymore

block = script.Parent

while wait(10) do
	block.BrickColor = BrickColor.new(105,14,0)
	function onTouched(Obj)
		local h = Obj.Parent:FindFirstChild("Humanoid")
		if h then
			h.Health = 0
			block.BrickColor = BrickColor.new(0,0,0)
		end
	end
	script.Parent.Touched:Connect(onTouched)
end

can someone help please?

2 answers

This is what you want?

local block = script.Parent 
	
	    block.BrickColor = BrickColor.new(105,14,0)
	    function onTouched(Obj)
	        local h = Obj.Parent:FindFirstChild("Humanoid")
                 if h then
	            h.Health = 0
	            block.BrickColor = BrickColor.new(0,0,0)
                    script.Disabled = true
                    wait(10)
                    script.Disabled = false
                    block.BrickColor = BrickColor.new(105,14,0)
	        end
	    end
	    script.Parent.Touched:Connect(onTouched)
	

If you want to make it randomly,try this

local block = script.Parent 
	coroutine.resume(coroutine.create(function()
             while true do
              script.Disabled = false
                     block.BrickColor = BrickColor.new(105,14,0)
                    wait(math.random(1,15))
              script.Disabled = true
                    block.BrickColor = BrickColor.new(0,0,0)
                    wait(math.random(1,15))
               
             end)
        end)
	    function onTouched(Obj)
	        local h = Obj.Parent:FindFirstChild("Humanoid")
                 if h then
	            h.Health = 0
	        end
	    end
	    script.Parent.Touched:Connect(onTouched)
	

1 comment

0

not exactly, the script waits until someone touches it but i want it to go off randomly rather than wait till someone touches it for it to loop

wait nvm i got it, i just inserted this script into serverscript service

kill = game.Workspace.Kill

while wait() do
	kill.KillScript.Disabled = true
	wait(3)
	kill.KillScript.Disabled = false
	wait(3)
end

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