Printing out a NumberValue that changes doesn't work

Hello! I want to make developer products for my game that gives a player cash depending on multiple stats that he has. I made a script for the developer products and it works fine, so now I want to make that the cash that the player receives changes depending on another stat that he has.
My idea is to create a NumberValue in ReplicatedStorage, this value gets updated by a script every .5 seconds (since the other stat the player gets is every .5 seconds), then take the Value of the NumberValues as the number of cash to implement to the player.

Here’s the script that I use to update the NumberValue: (StarterGUI, since it has other lines of code changing a Text Label in it)

local leaderstats = game.Players.LocalPlayer:FindFirstChild("leaderstats")
local Multi = leaderstats:FindFirstChild("Multiplier")

while wait(.5) do
	local formula = (Multi.Value/1.5)
	game.ReplicatedStorage.Cash1.Value = formula*100*(3600/2)
end

Here’s the developer product script (ServerScriptService):

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local StarerGui = game:GetService("StarterGui")

local productID = 1347531300

local function ProcessReceipt(ReceiptInfo)
	print("Proccessing reciept")

	local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
	if not Player then
		warn("Player is not ingame, not yet proccessed payment")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	print(string.format("%s has %i cash, incrementing by %i", Player.Name, Player.leaderstats.Cash.Value, game.Workspace["Usefull Informations"].DevProducts.Cash.Cash1.Value))

	Player.leaderstats.Cash.Value += game.ReplicatedStorage.Cash1.Value
	print("Purchase granted")
	print(game.ReplicatedStorage.Cash1.Value)
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = ProcessReceipt

So when I buy the developer product, here is the output I get:
image

If I change game.ReplicatedStorage.Cash1.Value by a value like I don’t know, 100, it works perfectly fine, so the problem doesn’t come from the developer product script itself. By the way, in the studio if I click on the value, it does change while in game:
image

I have no idea why it does this, please help!

2 Likes

You’re changing the ReplicatedStorage Number Value’s value on the client, therefore it won’t update for the server. You need to update the value on the server

1 Like

How could I do that? I never experienced this issue before

1 Like

Will there be multiple players in the game? If so, you’ll need a value for everyone.
It’d be best to make a folder with values for each player in ReplicatedStorage

You can use remote events to send stuff to the server as arguments

CLIENT
game.ReplicatedStorage.YOURREMOTEVENT:FireServer(FORMULARESULT)

Server
Game.ReplicatedStorage.YOURREMOTEVENT.OnClientEvent:Connect(function(plr, result)
– Update value
end)

1 Like

Yes there will be multiple players on the game.
Ima try to use your remote for the server since it’s what I need.

3 Likes