HumanoidStateType.Dead not working?

I was experimenting with some properties of the humanoid and I’m a fairly beginner scripter so I wanted to test out somethings. I created a part in the workspace and added a script to it with this code inside of it.

local pt = script.Parent
local deb = true

pt.Touched:Connect(function(plr)
	if plr.Parent:FindFirstChild("Humanoid") then
		if deb == true then
			deb = false
			print(plr.Parent.Name)
			local hum = plr.Parent:WaitForChild("Humanoid")
			hum:ChangeState(Enum.HumanoidStateType.Dead)
			--[[
			local humh = hum.MaxHealth	
			hum:TakeDamage(humh)

			local currentState = hum:GetState()
			print(currentState)
			]]--
			wait(3)
			deb = true
		end
	end
end)

It seems that it does pretty much nothing when it comes to changing the state of the humanoid even if I set the state type to jumping instead of dead. I did a test with TakeDamage as shown in the notes in the code and it worked so I’m not sure what the issue with it is, anyone have any ideas?
I know there’s a lot easier ways to do this, I’m just experimenting out of curiosity.

1 Like

I’m not too sure but I think that changing the state to dead doesn’t do anything and that its just there so that when you do die you can check the humanoidstate to see if you’re dead.

That’s what I thought it might be too, but on the api for HumanoidStateType it says this:
The Humanoid died. Changing a Humanoid’s state to this one will kill it.

are you doing it on the client or server.

Well it’s in a server script so I’m pretty sure that it’s running on the server.

local Part = script.Parent
local Debounce = false

Part.Touched:Connect(function(Part)
if Part.Parent:FindFirstChildOfClass("Humanoid")
if not Debounce then
Debounce = true
local Character = Part.Parent
print(Character.Name)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
Humanoid:ChangeState(Enum.HumanoidStateType.Dead)
wait(3)
Debounce = false
end
end
end)

I’m not sure but this might work

It didn’t work oddly enough, there isn’t any other scripts anywhere that would be affecting the Humanoid so I’m not sure why that didn’t work.

how to fix stubborn script:

local pt = script.Parent
local deb = true

pt.Touched:Connect(function(plr)
	if plr.Parent:FindFirstChild("Humanoid") then
		if deb == true then
			deb = false
			print(plr.Parent.Name)
			local hum = plr.Parent:WaitForChild("Humanoid")
			hum:ChangeState(Enum.HumanoidStateType.Dead)
            while hum:GetState() ~= Enum.HumanoidStateType.Dead do
                hum:ChangeState(Enum.HumanoidStateType.Dead)
            end
			--[[
			local humh = hum.MaxHealth	
			hum:TakeDamage(humh)

			local currentState = hum:GetState()
			print(currentState)
			]]--
			wait(3)
			deb = true
		end
	end
end)

please note that this is a no-brainer solution, even if it is a solution, lol.

This froze my studio, and then after it unfroze it said that the script exhausted it’s allowed execution time. I assumed it was because there was no wait on the while loop, so I added a .1 wait and omg! Nothing happened lol

Then that means that setting humanoid state to Enum.HumanoidStateType.Dead doesn’t work as the script has tried doing that so many times until the studio freezes and tells it to stop

When you added a .1 wait, now it tries to set the humanoid state perpetually until the script is deleted (but it can’t)

So uh simple solution:
humanoid.Health = 0

I believe the dead state is only for internal use and thus you cannot set humanoid state to it explicitly

Makes sense, I’ll just set this as the solution then, thank you