Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I increase MaxHealth instead of changing its value?

I tried to do line 22 and 23, but it won't work. It works fine with just changing the value, but I need it to be able to be adding not changing.

local touchers = {}
local DELAY = 5

function onTouched(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then 
        local plrTouching = false
        table.foreach(touchers, function(key, val)
            
            if val == plr then
                plrTouching = true
            end
        end)

        if not plrTouching then
            table.insert(touchers, plr) 

local stats = plr:findFirstChild("leaderstats")
		local cash = stats:findFirstChild("Cash")
		if cash.Value >= 150 then
		cash.Value = cash.Value - 150
		local MH = game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").MaxHealth --Maybe wrong
		MH.Value = MH.Value + 50 --its not working
		else 
	print("Not enough money!")
		end

            wait(DELAY) 
            for i = #touchers, 1, -1 do
                if touchers[i] == plr then
                   table.remove(touchers, i)
                end
            end
        end
    end
end
script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer
local touchers = {}
local DELAY = 5

function onTouched(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then 
        local plrTouching = false
        table.foreach(touchers, function(key, val)

            if val == plr then
                plrTouching = true
            end
        end)

        if not plrTouching then
            table.insert(touchers, plr) 

local stats = plr:findFirstChild("leaderstats")
        local cash = stats:findFirstChild("Cash")
        if cash.Value >= 150 then
        cash.Value = cash.Value - 150
		local MH = game.Workspace[plr.Name]:WaitForChild("Humanoid")
		MH.MaxHealth = MH.MaxHealth + 50
        else 
    print("Not enough money!")
        end

            wait(DELAY) 
            for i = #touchers, 1, -1 do
                if touchers[i] == plr then
                   table.remove(touchers, i)
                end
            end
        end
    end
end
script.Parent.Touched:connect(onTouched)

I think I've fixed it, I have no idea what you did wrong. EDIT : It was probably MH.Value that you did wrong

4 comments

0

Don't want to be rude, but try to explain what you've done in future to fix someone's code, otherwise there's no point in doing it as they can't learn from it...

0

I didn't how how I fixed it, that's why I didn't show how I fixed it, I was just playing around with those 2 lines

0

Lines 22 and 23 were changed

0

I understand it. so .Value is wrong. and has to be straight to MaxHealth, Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.