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

Humanoid Block Unanchor on Death Script won't work?

Asked by 5 years ago
Edited 5 years ago

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

1local h = game.workspace.Test.Head
2local b = game.workspace.Test.Humanoid
3 
4if b.Health == 0
5then h.Anchored = false
6h.CanCollide = true
7end

2 answers

Log in to vote
-1
Answered by 5 years ago

K so to start, a debounce will be needed. you will also need to loop the if condition.

01local h = game.workspace.Test.Head
02local b = game.workspace.Test.Humanoid
03local debounce=false
04while true do
05if b.Health == 0 and debounce=false
06then
07debounce=true
08h.Anchored = false
09h.CanCollide = true
10wait(0.1)
11debounce=false
12end
13 
14wait(0.1)--keep this here otherwise it runs 30 times a second
15end

tell me if it helped :)

0
Error in output, Workspace.Test.Script:5: 'then' expected near '=' xpertroblox3r 5 — 5y
0
make line five debounce=false into debounce==false EmbeddedHorror 299 — 5y
0
I changed that & added a line "h.Anchored = true" above local debounce = false and now it works great! thanks xpertroblox3r 5 — 5y
Ad
Log in to vote
1
Answered by
Elixcore 1337 Moderation Voter
5 years ago
Edited 5 years ago

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!

1local h = workspace.Test.Head
2local b = workspace.Test.Humanoid
3 
4 
5b.Died:Connect(function() -- Connecting to .Died
6    h.Anchored = false
7    h.CanCollide = true
8end)
0
I tried this one as-well and it didn't seem to work unfortunately. Thankyou though, i've learned more from your help :) Will be sure to try this in the future xpertroblox3r 5 — 5y
0
Tested in roblox studio on a baseplate, script works, sorry you could not make it work. Elixcore 1337 — 5y

Answer this question