Script very broken

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

What is dps.Value? Can you show where you change it?

dps.Value is in the players Data, which the value would be 175 in the video

How many times does it subtract? Is the value ever edited by a script?

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

1 Like

no, it was subtracted by a lot in the video. It originally was suppose to be subtracted by the added value in damage

Im not really getting it

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

1 Like

Ohhh, now i understand. Do i put it outside of the loop or something?

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?

Oh, armor can increase the amount of damage a certain player does, thats the only reason i named it that

1 Like

And i tried putting it outside of the loop but that didn’t work

How is the armour being attached to the character? Is it via welds or is it accessories?

its being attached by welds

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.

Right before you change the dps print something it can be anything. See how many times it prints.

I did this

elseif condition == "Un-equipped" then
		plr.Data.Damage.Value = plr.Data.Damage.Value - dps.Value
		print("Working")

And it printed working but didn’t do anything

Change to

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

nope, still doesn’t get subtracted

From the looks of it, the value is being subtracted multiple times.