As I wanted to make a revive spell, my script wasn’t working.
I did:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
player.Chatted:Connect(function(msg)
if msg == "!revive" then
char.Humanoid.Health = 50
end
end)
end)
end)
I don’t think you can make the player health go back up after its dead. Try making it so you are downed at 5 health and can not be damaged and maybe then do the spell?
Make sure it’s disabled upon spawning (CharacterAdded), or, check prior to that the difference between the Humanoid’s current health and the upcoming damage, so you can disable the state prior to that.
As long as the Humanoid never dies, things like FloorMaterial can be seen and calculated, which helps developers with (for example) things like ground impacts.
So your method works too as you said, it’s all about not making the Humanoid die in the end.
Id recommend moving the Chatted event out of the CharacterAdded event as this may cause a large memory leak. Every time the character dies, it will add an additional event. These events will gather up, and lets say the character had died 100 times, the next time the character chats, it will set char.Humanoid.Health = 50 100 times instead of once. This can be very dangerous and will cause large amounts of lag every time you run that command.
That is not a possible thing to do. Once a Humanoid has 0 health, it will automatically have its state as “Dead”, which can not be changed. Once the player respawns, the old character is destroyed & Roblox requests a new one, that’s how you respawn.
What I suggest doing: Making a player’s Humanoid have, for example, 120 max health. Whenever the health is only 20 or below, down the player, the they can get revived if someone types “!revive”
Here’s an example script:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
humanoid:SetAttribute("Downed",false)
humanoid.HealthChanged:Connect(function()
if humanoid.Health <= 20 then
humanoid:SetAttribute("Downed",true)
--you can put other downed limitations here
else
if humanoid:GetAttribute("Downed") then
humanoid:SetAttribute("Downed",false)
end
end
end)
end)
player.Chatted:Connect(function(text)
if text == "!revive" then
if player.Character and player.Character.Humanoid:GetAttribute("Downed") then
player.Character.Humanoid.Health = 50
end
end
end)
end)
Also please don’t put player.Chatted when to CharacterAdded events, otherwise that might cause some memory issues. The event does not get disconnected whenever the signal is fired again.