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

How do i make a killbrick that goes off randomly?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)


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 mynam3with123 65 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question