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 4 years ago
Edited 4 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

local h = game.workspace.Test.Head
local b = game.workspace.Test.Humanoid

if b.Health == 0
then h.Anchored = false
h.CanCollide = true
end

2 answers

Log in to vote
-1
Answered by 4 years ago

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

local h = game.workspace.Test.Head
local b = game.workspace.Test.Humanoid
local debounce=false
while true do
if b.Health == 0 and debounce=false 
then 
debounce=true
h.Anchored = false
h.CanCollide = true
wait(0.1)
debounce=false
end

wait(0.1)--keep this here otherwise it runs 30 times a second
end

tell me if it helped :)

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

local h = workspace.Test.Head
local b = workspace.Test.Humanoid


b.Died:Connect(function() -- Connecting to .Died
    h.Anchored = false
    h.CanCollide = true
end)
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 — 4y
0
Tested in roblox studio on a baseplate, script works, sorry you could not make it work. Elixcore 1337 — 4y

Answer this question