Can add to IntValue but can't seem to subtract

Hello everyone,
I’m trying to make a system where by touching a part, the players’ gun damage increases/decreases.
The script works fine whenever the Value is positive, but whenever it is negative, the damage value doesn’t change at all.

I’ve tried doing this:

player.weaponStats.Damage.Value = newValue.Value

to see if the damage value even changes when the newValue.Value is negative, but nope. It stays at the default value.

I’m really lost here but I feel like I’m missing something obvious :sweat_smile:

game.Players.PlayerAdded:Connect(function(player)
	local part = script.Parent.Parent
	local SurfaceGui = script.Parent
	local TX = script.Parent.TextLabel
	local MinusPlus = math.random(1,2)
	local newValue = TX.New
	local active = false
	newValue.Value = math.random(-150,300) 
	if newValue.Value < 0 then
		TX.Text = newValue.Value
		part.Color = Color3.fromRGB(170, 0, 0)
	else
		TX.Text = "+" .. newValue.Value
		part.Color = Color3.fromRGB(85, 170, 0)
			
	part.Touched:Connect(function(hit)
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if not active then
				active = true
					player.weaponStats.Damage.Value += newValue.Value 
				wait(5)
				active = false
			end
			end
			end)
	end
end)
1 Like

You appear to be using 2 Different Player Variables

2 Likes

Oops yeah, fixed that. Still though, subtracting isn’t working :frowning:

1 Like

Put your script into StarterGui, that may be the reason its not working

2 Likes

Try using

player.weaponStats.Damage.Value -= newValue.Value

2 Likes

I was definitely missing something obvious haha. I forgot to put end on here.
It works perfectly now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.