Why is value being added but not subtracted?

Hello!, so im added a value and thats working fine but when i subtract a value there are no errors but it’s not subtracting any values

 	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 -- Player's Damage isn't being subtracted
			end
		end
	end

Is the value of dps 0? If it ain’t zero, how are oyu trying to get the value of dps?

1 Like

It’s being fired from a remote
Server

game.ReplicatedStorage.Events.EquipArmor.OnServerEvent:Connect(function(plr, armor, condition, dps)

Client

	Events.EquipArmor:FireServer(armor.Name, "Un-equipped", dps.Value)

Okay huh? You already obtained the value, why are you trying to get the .Value of a number? Change dps.Value in the OnServerEvent to dps

1 Like

when i try that it gives an error saying that i can’t subtract it

Okay before trying to subtract, print what’s inside of dps, Also what error are you getting?


Oh, i didn’t realize i had this

local dps = plr:WaitForChild("Data").EquippedValue
1 Like

That’s probably why, conflictions, rename that so it wont conflict with the parameter

But now it’s saying nil value when their is value

It prints this now

Sho w the full code so I can see whats’ going on, or just the event onserverevent

local armorFolder = game.ReplicatedStorage.Equipment

game.ReplicatedStorage.Events.EquipArmor.OnServerEvent:Connect(function(plr, armor, condition, dps)
	print(dps)
	plr.Data.Damage.Value = plr.Data.Damage.Value + dps
	
	if condition == "Equipped" then
		for index, equippedArmor in pairs(plr.Character:GetChildren()) do
			
			if equippedArmor:IsA("Model")and armor then
				equippedArmor:Destroy()
			end
		end
		for index, chosenArmor in pairs(armorFolder:GetChildren()) do
			if chosenArmor.Name == armor then
				local chosen = chosenArmor:Clone()
				chosen.Parent = plr.Character
				
				for index, armorParts in pairs(chosen:GetChildren()) do
					for index, playerParts in pairs(plr.Character:GetChildren()) do
						if playerParts:IsA("BasePart") then
							if armorParts.Name == playerParts.Name then
								armorParts.PrimaryPart.CFrame = playerParts.CFrame
								local weld = Instance.new("WeldConstraint")
								weld.Part0 = playerParts
								weld.Part1 = armorParts.PrimaryPart
								weld.Parent = armorParts.PrimaryPart
							end
						end
					end
				end
			end
		end
	elseif condition == "Un-equipped" then
		for index, equippedArmor in pairs(plr.Character:GetChildren()) do
			if equippedArmor:IsA("Model") then
				equippedArmor:Destroy()
				print(dps)
				plr.Data.Damage.Value = plr.Data.Damage.Value - dps 
			end
		end
	end
end)

And how are you firing the event again in terms of parameters?? Print the dps value on the client to see what it is be

It prints 153 on client

	Events.EquipArmor:FireServer(armor.Name, "Un-equipped", dps.Value)

Okay how is it detecting nil, maybe put dps.Value in a variable and fire that variable?

local dpsval = dps.Value
Events.EquipArmor:FireServer(armor.Name, "Un-equipped", dpsval)

oof, it still gives off the same error as before

Why is it printing nil?

Now i made a change and it’s printing 0?

What did you change to cause that?

In the script their is 2 events being fired, one is. And i just added dpsval to the first one to make it print 0

Events.EquipArmor:FireServer(armor.Name, "Equipped", dpsval)

And the other is

Events.EquipArmor:FireServer(armor.Name, "Un-equipped", dpsval)

The weird thing is that their is a value to dpsval but it prints 0