What do you want to achieve? A script that will print (dead) when the character’s humanoid health is at 0 (i dont want to kill then as they will be revived)
What is the issue? the script doesn’t detect health change after i set the humanoids dead state to false.
What solutions have you tried so far? I have tried using humanoid.HealthChanged and a while true do loop but neither one have worked
here’s the script
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if character:GetAttribute("Species") == "Heretic" then
local humanoid = character.Humanoid
character.Humanoid:SetStateEnabled("Dead", false)
humanoid.HealthChanged:Connect(function(health)
if health <= 0 then
print("dead")
end
end)
end
end)
end)
Once a humanoid enters the dead state, it can’t be brought back, as the humanoid is ‘killed’ at that point.
char:GetAttributeChangedSignal("Health"):Connect(function()
local currentHealth = char:GetAttribute("Health")
if currentHealth <= 0 then
--//do stuff
end
end)
Try this? It detects whener a Humanoid health’s reached 0 or dead
local players = game.Players
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
if humanoid then
if humanoid:GetState() == Enum.HumanoidStateType.Dead then
print("Dead")
end
end
end)
end)
This would work under normal circumstances, however in this instance, you want to register the character as “Dead”, but, you don’t want the actual character to die because you will respawn when you do.
Btw, Why can’t she just set the Respawn Time in a large number, And Loadthecharacter once the targetting event was done. There is a lot of way to do this such as setting an Attribute and also the setting a value into a player to define as " Health "
When your character respawns it respawns your original character, but what if before you died you had these int values or number values, or anything for that matter that are crucial to the game. Once you die you lose all those things, of course to solve that you can readd those but you will need to know what those values were before they died, so you can put them back to normal. So it would be much easier to fake “Died” instead of actually dying.
Yes, but when you die you would have to save it to the data store and when you load in you would have to get it from the data store, then simply you can avoid all the hassle of doing so.
Also, I believe DataStores can have a tendency to not save when you use them too often, and this may be a game where you die often.
I’ve been having the same issue recently and it seems that the character is being added before CharacterAdded can be run. Here’s the edited version of your script that should work:
game.Players.PlayerAdded:Connect(function(player)
if player.Character then
local character = player.Character
if character:GetAttribute("Species") == "Heretic" then
local humanoid = character.Humanoid
character.Humanoid:SetStateEnabled("Dead", false)
humanoid.HealthChanged:Connect(function(health)
if health <= 0 then
print("dead")
end
end)
end
end
player.CharacterAdded:Connect(function(character)
if character:GetAttribute("Species") == "Heretic" then
local humanoid = character.Humanoid
character.Humanoid:SetStateEnabled("Dead", false)
humanoid.HealthChanged:Connect(function(health)
if health <= 0 then
print("dead")
end
end)
end
end)
end)
I’d also recommend using a function to handle this to avoid repeating code.