Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Humanoid Block Unanchor on Death Script won't work?

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

✓ Accepted answer

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 :)

3 comments

0

Error in output, Workspace.Test.Script:5: 'then' expected near '='

0

make line five debounce=false into debounce==false

0

I changed that & added a line "h.Anchored = true" above local debounce = false and now it works great! thanks

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)

2 comments

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

0

Tested in roblox studio on a baseplate, script works, sorry you could not make it work.

This discussion is preserved as it was. New answers, comments, and votes are closed.