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

how do i make it so once a player's health goes below 100, their maxhealth goes back to 100?

Asked by 6 years ago

for example, if i change the maxhealth to 150, the player's health will go to 150. when their health goes below 100, the maxhealth goes back to 100. this works fine only the first time. every time after that, the maxhealth changes back to 100 after i change it

local lp = game.Players.LocalPlayer
local char = lp.Character or lp.CharacterAdded:wait()
local ad = script.Parent
local frame = script.Parent
local humanoid = char:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(function()
    repeat
    wait(1)
    if humanoid.MaxHealth > 100 then
        frame.Visible = true
    end
    until frame.Visible == true 
    local health = humanoid.Health - 100
    ad.Size = UDim2.new(health/100,0,1,0)
    if humanoid.MaxHealth > 100 then
        if humanoid.Health < 100 then
            frame.Visible = false
            humanoid.MaxHealth = 100
        end
    end
end)
0
Roblox should already do this. I'm pretty sure the character model resets every time you die, so you do not need a script for this. hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

try this script

local health = game.Players.LocalPlayer.Character.Health

if health == 100 then
    --Anything you want if health is 100
elseif health < 100 then
    health = 100
end
0
Sorry if this is wrong... I suck at math xD Goldenkings11 -11 — 6y
0
You needed to specify the humanoid after character. The humanoid contains the health property, not the module. hiimgoodpack 2009 — 6y
Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

I think this is what you mean?

local lp = game.Players.LocalPlayer
local char = lp.Character or lp.CharacterAdded:wait()
local ad = script.Parent
local frame = script.Parent
local humanoid = char:WaitForChild("Humanoid")


humanoid.HealthChanged:Connect(function()
    if humanoid.MaxHealth > 100 then 
        frame.Visible = true
        -- Set health to 100 if we go below 100
        if humanoid.Health < 100 then 
            humanoid.MaxHealth = 100
            frame.Visible = false
        end
    else
        -- Doesn't let you set MaxHealth below 100
        humanoid.MaxHealth = 100
    end
    humanoid.Health = humanoid.MaxHealth
end)

Answer this question