Values wont add

I am attempting to add 2 values, however though it wont work. No specific errors show up on the output that are related to the script, may someone help?

local BuyAndSellAmount = script.Parent
local number = script.RandomizeValue


while true do
	number.Value = math.random(1,6)
	wait(5)
	if number.Value == 1 then

		print("+1")
		BuyAndSellAmount.Value = BuyAndSellAmount.Value + 1
		
	elseif number.Value == 2 then
	
		print("+0.1")
		BuyAndSellAmount.Value = BuyAndSellAmount.Value +  0.1

	elseif number.Value == 3 then
		
		print("+2")
		BuyAndSellAmount.Value = BuyAndSellAmount.Value + 2

	elseif number.Value == 4 then
		
		print("-1")
		BuyAndSellAmount.Value = BuyAndSellAmount.Value - 1

	elseif number.Value == 5 then
		
		print("-0.1")
		BuyAndSellAmount.Value = BuyAndSellAmount.Value - 0.1

	elseif number.Value == 6 then

		
		print("-2")
		BuyAndSellAmount.Value = BuyAndSellAmount.Value - 2

    


	end	
end

Thank you!

the code you provided works fine

If it’s a datastore system try this unless you already done it?
Studio > Home > Game Settings > Security


If it’s not then try:

  1. Checking if the parent is a NumberValue
  2. Checking if the number location is a NumberValue
  3. Decreasing the wait() you might of thought it wasn’t working cause 5 seconds is sort of a long time

Sorry, I really don’t see anything wrong with your code.

1 Like

The parent was a numbervalue so i changed it to a intvalue, still didnt work

I also decreased the wait(), didnt work

So yeah

Is your script a local script or a server script or a module script?

It is a serverscript, so yeah.

Does the IntValue already have a set value? If not, you can change it to 0. You can also switch

BuyAndSellAmount.Value = BuyAndSellAmount.Value + 1
-- into
BuyAndSellAmount.Value += 1

It doesn’t have a set value. Changed it to that but still didnt work.

Strange, I have mine in a GUI.

Nvm, it only works in the workspace

At the beginning of the game, the starterGui is duplicated into every player, just like the starterpack. By writing the code inside of a script will only change the player’s gui value, not the gui in ‘starterGui’