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).
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
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.
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
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
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.
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
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