#StateEnabled not functioning? I could be going crazy.

1 messages · Page 1 of 1 (latest)

tame nexus
#

What did I do wrong, I think I'm going crazy because I do not know what's going on.

local model = script.Parent
local hum = model.Humanoid

hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

hum.HealthChanged:Connect(function(hp)
    if hp <= 0 then
        print("dead")
    end
end)

The humanoid, dies.. it breaks it's bones, if I remove,

hum.HealthChanged:Connect(function(hp)
    if hp <= 0 then
        print("dead")
    end
end)

it works.. what?

shut holly
#

You're killing the humanoid before you connect the function

tame nexus
#

the state enabled

#

it shouldn't die

#

but it is 💀

mellow pagoda
#

Enabling the Dead state is what allows the Humanoid to die

tame nexus
#

WAIT

#

OH MY BAD

#

I forgot to make the text to false

tame nexus
tame nexus
#

however it's not working

mellow pagoda
#
--!strict
local Players = game:GetService("Players")



local function onHealthChanged(health: number)
    if health > 0 then
        return
    end
    
    print("Died")
end

local function onCharacterAdded(character: Model)
    local humanoid = character:FindFirstChildOfClass("Humanoid") :: Humanoid
    
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
    humanoid.HealthChanged:Connect(onHealthChanged)
    humanoid.BreakJointsOnDeath = false
end

local function onPlayerAdded(player: Player)
    local character = player.Character
    
    if character then
        onCharacterAdded(character)
    end
    
    player.CharacterAdded:Connect(onCharacterAdded)
end



for _, player in Players:GetPlayers() do
    onPlayerAdded(player)
end

Players.PlayerAdded:Connect(onPlayerAdded)
#

Works fine for me