Variable not updating?

Hello everyone,

I have a small problem when it comes to updating a variable, and I cant seem to find a solution so I thought I’d ask here.

The problem is that when I try to update the variable, it simply won’t. It just stays the old value.

This might be some basic issue but I honestly cant get it figured.


-- Pulling data
local CurrentData = ReplicatedStorage.RemotesExternal.RequestData:InvokeServer()
local MicrophonesOwned = CurrentData[3]

function UpdateData()
	local newData = ReplicatedStorage.RemotesExternal.RequestData:InvokeServer()
	-- Printing "newData[3]" prints the table I need, now I want to apply it to the variable.
	MicrophonesOwned = newData[3]

-- Assuming the data has updated on the server, and the client wants their data
-- We will run the UpdateData() function

function Purchase()
	-- Prints the old values, instead of the new updated one. Why?

-- Assuming the player has pressed a button to purchase something, we run the Purchase() function


1 Like

Try adding a wait before calling Purchase() because it might be the change hasn’t finished (or smth like that)

The Purchase() function is being called by a MouseButton1Click Event, I left it out of this post.
So I think theres a lot of time in between.

When is the UpdateData being called.

UpdateData is being called once a purchase has been completed. (Which is why I want to update the table with the items owned) And when putting a print statement inside of the UpdateData function, it is being called. The problem is it wont update the variable