So im not sure why but im using -= to subtract something but when i do so the value gets into the negatives, in the video the value should be subtracted by 175 but instead subtracted by a lot
elseif condition == "Un-equipped" then
for index, equippedArmor in pairs(plr.Character:GetChildren()) do
plr.Data.Damage.Value = plr.Data.Damage.Value - dps.Value
if equippedArmor:IsA("Model") then
equippedArmor:Destroy()
end
end
end
It’s going to subtract 175 once for each child of plr.Character, since plr.Data.Damage.Value is the same object for each iteration of the loop (a loop invariant).
“equippedArmor” isn’t just each armor piece, it’s every body part, the humanoid, etc… you’re looping over ALL the children inside the player character model. So it’s going to subtract 175 at least 20 times, possibly more if they have accessories on.
If you have to add up the armor values for each piece being removed, it would go inside the loop, inside the if statement. If it’s just one total value you are subtracting, regardless of how much armor they have, it should go outside the loop.
Not sure why it’s called Damage and dps though, I would think that would be the damage they do based on weapons. Wouldn’t removing armor affect their armor value? Is it just a naming thing, like armor here is actually weapons?
Alright, why not parent the armour to a folder inside of the character called something like “PlayerArmour”, and then when the condition is “Un-equipped”, iterate through the children of the PlayerArmour instead of iterating through the children of the character?
You could instead have something to discern the armour for the rest, such as a value or attribute inside of the armour. Then when iterating, check if this armour has this difference, and if so, then subtract the amount of damage the player does.
elseif condition == "Un-equipped" then
for index, equippedArmor in pairs(plr.Character:GetChildren()) do
if equippedArmor:IsA("Model") then
equippedArmor:Destroy()
plr.Data.Damage.Value = plr.Data.Damage.Value - dps.Value
end
end
end