How to fix my knife count

so this is my knife throw script, my bug is like when i throw a knife it go 29 and then when it regen to 35 or something when i throw again the value will become 28 and the value go to 0 when it regen i cant throw knife

		if Player.Backpack.Value.Knife.Value >= 1 then
			Player.Backpack.Value.Knife.Value = Player.Backpack.Value.Knife.Value - 1

is the script a local script???

1 Like

this is script inside the serverscriptservice

1 Like

put it in the tool and make it like

if script.Parent.Value >= 1 then
script.Parent.Value = script.Parent.Value - 1
end

its not the tool , i made it if the player press 1 key it fire the server and server script onserverevent

what is Player.Backpack.Value.Knife.Value?

i made a folder name Value and inside the folder it got a numbervalue call knife and the value of knifei

The problem here most likely isn’t caused by these two lines of code. You’ll need to share more if you want to have a decent chance at being helped. Anyways, even though I don’t have enough information to help solve your problem with, one improvement and knowledge nugget I can impart unto you is the wisdom of compound operators. They were first introduced in this release notes.

Compound operators were made to help shorten your code. All of them have virtually the same syntax, and just do different operations. The list of available ones are: += , -= , *= , /= , %= , ^= and ..=. The syntax for these is value (operation)= other values. For example, here I use the += operator:

numValue += 1 --adds '1' to numValue

which is equivalent to:

numValue = numValue+1 --adds '1' to numValue

It’s the same thing with the other ones as well. numValue -= 1 is equal to numValue = numValue-1 and so on.

Anyways, we need more of your code to actually see what’s causing the problem.