While Code's answer is sufficient barring the inaccurate code.
A more versatile method would be to re-add the health that was taken, another method is to constantly set the health but that's unnecessarily resource intensive.
Here's what I mean:
local InvincibleToggle = true
local function DoInvincible(Character, Toggle)
if Toggle == true and Character:FindFirstChild("Humanoid") then
Character.Humanoid.HealthChanged:connect(function(health)
Character.Humanoid.Health = Character.Humanoid.MaxHealth
end)
end
end
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:conenct(function(character)
DoInvincible(character, InvincibleToggle)
end)
end)
The function allows you to make other non-playable characters invincible as well.
Plus you can remove the PlayerAdded section and replace it with your own method of calling the function.
While you Can set a players health to infinite, some scripts will set it to zero thus resulting in instant death even with infinite health.
You might have problems with lag using this method as I haven't tested it yet, but it should serve whatever purpose you require it for to a decent enough degree.
Let me know if this was unhelpful :>
1 comment
http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched