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

01block = script.Parent
02 
03while wait(10) do
04    block.BrickColor = BrickColor.new(105,14,0)
05    function onTouched(Obj)
06        local h = Obj.Parent:FindFirstChild("Humanoid")
07        if h then
08            h.Health = 0
09            block.BrickColor = BrickColor.new(0,0,0)
10        end
11    end
12    script.Parent.Touched:Connect(onTouched)
13end

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?

01local block = script.Parent
02 
03        block.BrickColor = BrickColor.new(105,14,0)
04        function onTouched(Obj)
05            local h = Obj.Parent:FindFirstChild("Humanoid")
06                 if h then
07                h.Health = 0
08                block.BrickColor = BrickColor.new(0,0,0)
09                    script.Disabled = true
10                    wait(10)
11                    script.Disabled = false
12                    block.BrickColor = BrickColor.new(105,14,0)
13            end
14        end
15        script.Parent.Touched:Connect(onTouched)

If you want to make it randomly,try this

01local block = script.Parent
02    coroutine.resume(coroutine.create(function()
03             while true do
04              script.Disabled = false
05                     block.BrickColor = BrickColor.new(105,14,0)
06                    wait(math.random(1,15))
07              script.Disabled = true
08                    block.BrickColor = BrickColor.new(0,0,0)
09                    wait(math.random(1,15))
10 
11             end)
12        end)
13        function onTouched(Obj)
14            local h = Obj.Parent:FindFirstChild("Humanoid")
15                 if h then
16                h.Health = 0
17            end
18        end
19        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

1kill = game.Workspace.Kill
2 
3while wait() do
4    kill.KillScript.Disabled = true
5    wait(3)
6    kill.KillScript.Disabled = false
7    wait(3)
8end

Answer this question