I am a VERY new scripter, started relatively yesterday/today, i'm trying to make a humanoid block(wall barrier) for a zombie survival game. When the humanoid dies, I want the block to un-anchor and fall
Here's my script so far, and I can't seem to figure out why it won't work. Any help would be appreciated.
Model name Test
1 | local h = game.workspace.Test.Head |
2 | local b = game.workspace.Test.Humanoid |
3 |
4 | if b.Health = = 0 |
5 | then h.Anchored = false |
6 | h.CanCollide = true |
7 | end |
K so to start, a debounce will be needed. you will also need to loop the if condition.
01 | local h = game.workspace.Test.Head |
02 | local b = game.workspace.Test.Humanoid |
03 | local debounce = false |
04 | while true do |
05 | if b.Health = = 0 and debounce = false |
06 | then |
07 | debounce = true |
08 | h.Anchored = false |
09 | h.CanCollide = true |
10 | wait( 0.1 ) |
11 | debounce = false |
12 | end |
13 |
14 | wait( 0.1 ) --keep this here otherwise it runs 30 times a second |
15 | end |
tell me if it helped :)
Hey, xpert, to get into stuff like this I recommend using events, Humanoids have an event called .Died which gets called every time the humanoid's health reaches 0.
To complete the script all you have to do is connect it to a humanoid.Died event!
1 | local h = workspace.Test.Head |
2 | local b = workspace.Test.Humanoid |
3 |
4 |
5 | b.Died:Connect( function () -- Connecting to .Died |
6 | h.Anchored = false |
7 | h.CanCollide = true |
8 | end ) |