Number Value not changing

Im trying to change a number value when a button is pressed but it is not changing.

Here is the code:

m.ServeSoda = function(cooldown)
	local player: player = game.Players.LocalPlayer or game:GetService("Players"):WaitForChild("LocalPlayer")
	local playerGui: playerGui = player.PlayerGui
	local interface: interface = playerGui.SoftServeInterface
	
	local border = interface.Soda:WaitForChild("border")
	local mainFrame = interface.Soda:WaitForChild("mainframe")
	
	local function Ui()
		border.Visible = true
		mainFrame.Visible = true
		
		local nezt = mainFrame.next
		local previous = mainFrame.previous
		local dispense = mainFrame.dispense
		
		nezt.MouseButton1Down:Connect(function()
			print("Next")
			local currentNumber = mainFrame.Parent.currentNumber.Value
			
			currentNumber = currentNumber + 1
		end)
		dispense.MouseButton1Down:Connect(function()
			border.Visible = false
			mainFrame.Visible = false
		end)
	end
	Ui()
end;

line 19 to 24 to be exact
It prints “Next” but it doesn’t change the number

And this is where my numbervalue is located:
image

1 Like

this is because you are changing it inside a local script, meaning it would only change client sided and would not affect the server. you would have to change it to the server, using remotes sending from client to server.

Yes this is what I want, so basically it works but the server can’t see it right?

yes, that is right. so what is the problem?

its not changing number on the client
image

local currentNumber = mainFrame.Parent.currentNumber

currentNumber.Value += 1

can you try doing this? sorry if it might not work though

It worked, why though???
—fdsdf

do

local currentNumber = mainFrame.Parent.currentNumber
currentNumber.Value += 1

since if you’re gonna do currentNumber = currentNumber + 1 then you are only changing the saved property value (basically, you only should save a variable of a value if you want to read it, since when you save the Value property, you are saving a number instead of the actual instance and the property) but not changing the value’s value. also currentNumber = currentNumber + 1 and currentNumber += 1 just does the same thing.

2 Likes

Can you change the solution to the reply from TheLordGamer1820? He has a really good explanation incase people goes to this topic

2 Likes

I know this is resolved already, but why are you doing this?

	local player: player = game.Players.LocalPlayer or game:GetService("Players"):WaitForChild("LocalPlayer")
	local playerGui: playerGui = player.PlayerGui
	local interface: interface = playerGui.SoftServeInterface

This is part of a different script