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

Script can't set a players health to math.huge?

Asked by 8 years ago

So I have a script listening to a RemoteEvent to see when to give x client infinite health. Problem is, when it does get called it doesn't work at all. I don't understand why it doesn't because setting the players health to something like 300 works. The game does have FilteringEnabled, and no output is printed.

function GetHumanoidFromPlayer(Plr)
    if (Plr ~= nil) then
        if (Plr.Character ~= nil) then
            local Find = Plr.Character:FindFirstChild("Humanoid")
            if (Find) then
                return Find
            end
        end
    end
    return nil
end


InfHealth.OnServerEvent:connect(function(Plr)
    if (CheckAdmin(Plr)) then
        local Hum = GetHumanoidFromPlayer(Plr)
        if (Hum ~= nil) then
            Hum.MaxHealth = math.huge
        end
    end
end)
0
are you sure that it's actually *not* changing the health? When dealing with math.huge, the health regeneration script will regenerate all of the health in a single frame (due to it being effectively infinite). I'm not sure if you're going off of the fact that the health bar doesn't get damaged when you set the health to decide if it's working or not. Other than that, it's kind of hard to gather w User#11893 186 — 8y
0
...what the problem is from what you posted. User#11893 186 — 8y
0
I have a gui telling me what my current health is, when I change it to math.huge it doesn't do anything. Video: https://www.youtube.com/watch?v=v7bLWRJwhfA DangCoolIsReal 32 — 8y
0
And you're sure that your InfHealth event is actually running? You can't just type "math.huge" into the box, because "math.huge" can't be converted to a number directly. It will give you nil instead, which will then be converted to "0" when you try to set a number property User#11893 186 — 8y
0
Holy crap i'm dumb it was a spelling mistake... -.- http://i.imgur.com/8UjWmnM.png My bad! DangCoolIsReal 32 — 8y

1 answer

Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
8 years ago

Seems like this should be an easy fix.

function GetHumanoidFromPlayer(Plr)
    if (Plr ~= nil) then
        if (Plr.Character ~= nil) then
            local Find = Plr.Character:FindFirstChild("Humanoid")
            if (Find) then
                return Find
            end
        end
    end
    return nil
end

game.Players.PlayerAdded:connect(function(Plr)
plr.CharacterAdded:connect(function(char) -- I am hoping this is the right term for it..
if (CheckAdmin(Plr)) then
local Hum = GetHumanoidFromPlayer(Plr)
if (Hum ~= nil) then
Hum.MaxHealth = math.huge
Hum.Health = math.huge
end)
end)

Hope this works for you!

Ad

Answer this question