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
01 | block = script.Parent |
02 |
03 | while 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) |
13 | end |
can someone help please?
This is what you want?
01 | local 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
01 | local 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) |
wait nvm i got it, i just inserted this script into serverscript service
1 | kill = game.Workspace.Kill |
2 |
3 | while wait() do |
4 | kill.KillScript.Disabled = true |
5 | wait( 3 ) |
6 | kill.KillScript.Disabled = false |
7 | wait( 3 ) |
8 | end |