Here's my scenario: each player has 500 health and 500 "shield" which is essentially extra health. I've assigned shield to an IntValue inside a GUI and I want shield to be depleted before health. I created a RemoteFunction for defining damage to players and I also have a brick that is supposed to damage players when touched.
Here is the LocalScript (inserted inside a ScreenGUI):
--Remote functions
local damageInfantry = game.ReplicatedStorage.DamageInfantry
function damageInfantry.OnClientInvoke(player, humanoid, amount)
if shield.Value > 0 then
shield.Value = shield.Value - amount
if shield.Value < 0 then --More damage done than shield remaining
local difference = shield.Value * (-1)
humanoid:TakeDamage(difference)
end
else
humanoid:TakeDamage(amount)
end
end
Here is the server script (inserted inside the brick):
--Functions
function onTouch(part)
local character = part.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
if canDamage then
damageInfantry:InvokeClient(humanoid, 100)
canDamage = false
wait(1)
canDamage = true
end
end
end
This gives me an error: attempt to perform arithmetic on local 'amount' (a nil value) What am I doing wrong and is there a better way to handle damaging humanoids with this "shield" mechanic?
Thanks in advance.

3 comments
I suspected I might've messed that up, I'm pretty new to Lua lol. But then how would you suggest I define player on the server script? Is Players.PlayerAdded the best option?
Well, there are lots of ways. You can use player in touched event (you have to use GetPlayerFromCharacter). It’s up to you, just get the player.
Thank you so much! Everything works great now.