Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Health change or INFINITE HEALTH of the character in ROBLOX? [closed]

Asked by 6 years ago

Please help me out guys how do you change the amount of health your character has in a game.Does an infinite value even exist? Changing it such that it is saved everytime the character respawns.

0
If you want a gear to stop killing players, remove the scripts but leave the handle. SaudiPhilippines -5 — 4y

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 6 years ago

To do this, simply use math.huge!

Example in a server script:

wait(1)
local plrs = game.Players:GetPlayers() --Replace with target player/character
local chr = plrs[1].Character --Get player character

--Set both maxhealth and health to an infinite value
chr.Humanoid.MaxHealth = math.huge
chr.Humanoid.Health = math.huge


--Test the infinite values by repeatedly trying to damage the player.
while true do
    chr.Humanoid:TakeDamage(100)
    print("DAMAGE TAKEN")
    wait(1)
end
Ad
Log in to vote
0
Answered by
Griffi0n 315 Moderation Voter
6 years ago
Edited 6 years ago

Don't use while loops, bad practice.

In a server script

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    local ChangeHealth
    Player.CharacterAdded:Connect(function(Character)
        if ChangeHealth ~= nil then
            ChangeHealth:Disconnect()
        end
        local Humanoid = Character:WaitForChild("Humanoid")
        local MaxHealth = 2147483647

        Humanoid.MaxHealth = MaxHealth
        ChangeHealth = Humanoid.HealthChanged:Connect(function()
            Humanoid.Health = MaxHealth
        end)
    end)
end)