Extended Health Not Working?

My armor tool, when equipped, adds extra MaxHealth to the user. The health text shows the extra added 80 hp when the armor is equipped, but when the user gets damaged, the damager ignores the armor (extra max health).

before bruh armor

code:

local tool=script.Parent
local handle=tool.Handle
local h = tool.Parent:FindFirstChild(“Humanoid”)
local remotefunction=tool.RemoteFunction
local debris=game:GetService(“Debris”)

function remotefunction.OnServerInvoke(player,command,value)
if command==“protect” then
if value[100] then
local currentvest=value[1]:FindFirstChild(“VestArmour”)

	end
	local vest=Instance.new("Hat")
	vest.Name="VestArmour"
	handle:Clone().Parent=vest
	vest.AttachmentPos=Vector3.new(0, 1.8, 0.1)
vest.Parent=value[1]


	
tool.Handle.Transparency = 1
tool.Handle.Crowns.Transparency = 1
tool.Handle.Shield.Transparency = 1
tool.Handle.Pocket1.Transparency = 1
tool.Handle.Pocket2.Transparency = 1
tool.Handle.Pocket3.Transparency = 1


wait(2)
tool.Handle.Transparency = 0

	tool.Handle.Crowns:Destroy()
	tool.Handle.Shield:Destroy()
tool.Handle.Pocket1:Destroy()
tool.Handle.Pocket2:Destroy()
tool.Handle.Pocket3:Destroy()



	local h = tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		h.MaxHealth = h.MaxHealth + 45
		h.Health = h.Health + 45
		
	
	
	tool:Destroy()
	end
end
end
1 Like

Maybe because the line of code that handles the Add MaxHealth and Health is on localscript

If so, this means that the Add Health and MaxHealth is working but on the client-sided only not on the server thats why the Players health from the server has not changed at all.

1 Like

How would I fix this? I don’t know too much about scripting.

From what I can see on the code, it doesn’t use any form of client-sided stuffs (all relies on the server), So, you can just create a normal Script and copy this code and paste it in the created Script

there’s actually another part. The script shown above is in a normal scriptm while the one here is in a

local player=game.Players.LocalPlayer
local character=player.Character
local humanoid=character.Humanoid

local tool=script.Parent
local handle=tool.Handle
local h = tool.Parent:FindFirstChild(“Humanoid”)
local event=tool:WaitForChild(“RemoteFunction”)
local protection= 11

local ready=true

local debris=game:GetService(“Debris”)
local specialanim=humanoid:LoadAnimation(tool.special)

tool.Activated:connect(function()
local hum=character:FindFirstChild(“Humanoid”)
if hum and ready then
ready=false
specialanim:Play()
h.MaxHealth = h.MaxHealth + 45

	h.Health = h.Health + 45
	
	
	
	event:InvokeServer("protect",{character,hum,protection})
	ready=true
end

end)

do I change the local script one to a normal script, or do i change the first script above to a local script.

Wait… I’m currently reading the codes.

ignore the protection thing. it was supposed to reduce damage, but doesn’t work, and if i remove it the whole script breaks.

What is the purpose of value[100] when there is only 3 index-value in the table you passed?

i kinda thought that was another value that also determined protection. it didn’t work and i forgot to revert it

You need to change the max health first before the health.

i did. im trying to make the armor stack, so i did the “h.MaxHealth = h.MaxHealth + 45”, and it stacks, but it doesn’t work.

I’m pasting it here because it makes me hard to read the code format you given for us.

--Localscript (Parent => Tool):
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

local tool = script.Parent
local handle= tool.Handle
local h = tool.Parent:FindFirstChild("Humanoid")
local event = tool:WaitForChild("RemoteFunction")
local protection = 11

local ready = true

local debris = game:GetService("Debris")
local specialanim = humanoid:LoadAnimation(tool.special)

tool.Activated:connect(function()
    if humanoid and ready then
        ready=false
        specialanim:Play()
        
    	event:InvokeServer({character, hum, protection})
    	
    	ready = true
    end
end)
--Script (Invoking)
local tool=script.Parent
local handle=tool.Handle
local h = tool.Parent:FindFirstChild("Humanoid")
local remotefunction=tool.RemoteFunction
local debris=game:GetService("Debris")

function remotefunction.OnServerInvoke(player, value)
    
	local vest = Instance.new("Hat")
	vest.Name = "VestArmour"
	handle:Clone().Parent = vest
	vest.AttachmentPos= Vector3.new(0, 1.8, 0.1)
    vest.Parent= value[1]
    	
    tool.Handle.Transparency = 1
    tool.Handle.Crowns.Transparency = 1
    tool.Handle.Shield.Transparency = 1
    tool.Handle.Pocket1.Transparency = 1
    tool.Handle.Pocket2.Transparency = 1
    tool.Handle.Pocket3.Transparency = 1
    
    wait(2)
    tool.Handle.Transparency = 0
    
	tool.Handle.Crowns:Destroy()
	tool.Handle.Shield:Destroy()
    tool.Handle.Pocket1:Destroy()
    tool.Handle.Pocket2:Destroy()
    tool.Handle.Pocket3:Destroy()
    
	local h = tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		h.MaxHealth = h.MaxHealth + 45
		h.Health = h.Health + 45
	    tool:Destroy()
	end
end

What do you mean by stacks? Did you add the 45 to Health after adding the max health

ok so if i set the maxHealth to a certain value and wear another armor item, it wouldn’t stack. but if i use that code, it will, but the health won’t work.

TYSM IT WORKED (30 word not bypass)

1 Like

Ive tried to clean some and change some of your given code and added some comments.

Localscript:

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

local tool = script.Parent
local handle= tool.Handle
local h = tool.Parent:FindFirstChild("Humanoid")
local event = tool:WaitForChild("RemoteFunction")
local protection = 11

local ready = true

local debris = game:GetService("Debris")
local specialanim = humanoid:LoadAnimation(tool.special)

tool.Activated:connect(function()
    if hum and ready then
        ready = false
        specialanim:Play()
        
        -- Removed the MaxHealth and Health because it's not reliable since it will only replicate in client not on the server (it means it will not changed on the server)
        
    	event:InvokeServer("protect", {character, humanoid, protection})
    	
    	ready = true
    end
end)

Script:

local tool = script.Parent
local handle = tool.Handle
--local h = tool.Parent:FindFirstChild("Humanoid") --Useless as the parameter of OnServerInvoke has one humanoid
local remotefunction = tool.RemoteFunction
local debris = game:GetService("Debris")

function remotefunction.OnServerInvoke(player, command, value)
    if command == "protect" then
        if not value[1]:FindFirstChild("VestArmour") then --Will check if there are currently VestArmour in the player's Character
        	local vest = Instance.new("Hat")
            vest.Name = "VestArmour"
            handle:Clone().Parent = vest
            vest.AttachmentPos= Vector3.new(0, 1.8, 0.1)
            vest.Parent= value[1]
            
            tool.Handle.Transparency = 1
            tool.Handle.Crowns.Transparency = 1
            tool.Handle.Shield.Transparency = 1
            tool.Handle.Pocket1.Transparency = 1
            tool.Handle.Pocket2.Transparency = 1
            tool.Handle.Pocket3.Transparency = 1
        end
        
        wait(2)
        tool.Handle.Transparency = 0
        
    	tool.Handle.Crowns:Destroy()
    	tool.Handle.Shield:Destroy()
        tool.Handle.Pocket1:Destroy()
        tool.Handle.Pocket2:Destroy()
        tool.Handle.Pocket3:Destroy()
        
        
        --[[
    	local h = tool.Parent:FindFirstChild("Humanoid") --This maybe the cause (Maybe it can't find the Humanoid so the addition of MaxHealth and Health are not working)
    	
    	if (h ~= nil) then
    		h.MaxHealth = h.MaxHealth + 45
    		h.Health = h.Health + 45
    	    tool:Destroy()
    	end
    	]]
    	
    	
    	--Since there's a parameter of Character in the OnServerInvoke then just get the Humanoid in there.
    	--Like this
    	local h = value[2]:FindFirstChild("Humanoid")
    	if h then
    	    h.MaxHealth = h.MaxHealth + 45
        	h.Health = h.Health + 45
            tool:Destroy()
    	else
    	    warn("Humanoid not found.") --Debugging (You can remove this if you want to.)
    	end
    end
end

Check if it gotten some errors

it works if the tool is in the workspace, but it won’t even work or put it when i put it in the starterpack or use a give brick

Armor Equip Inventory Error - YouTube.

this is what happens if i put it into the starter pack. in the video, i’m clicking on the tools like I normally would to equip the armor. it works if i drop it and pick it back up, but how do i make it work as normal

Is there any error in the Output or Console?