Value is not changing, no error is showing!

Greetings,

I am making a kind of passive income business mechanic for my game and the game does not take money from cash.value. My script is down below:

game.ReplicatedStorage.Businesses.Business1Bought.OnServerEvent:Connect(function(player, cash, folder, business1bought)
	local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash").Value
	print("Business1 event succesfully received by script for player: " ..player.Name)
	cash = cash - 50
	print("Business1 owned by " ..player.Name.. " has started producing.")
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has produced 5$ worth of products.")
	cash = cash + 5
	wait(60)
	print("Business1 owned by " ..player.Name.. " has expired")
	local business1expired = game.ReplicatedStorage.Businesses.Business1Expired
	business1expired:FireClient(player, cash, folder, business1expired)
end)

Please help, if you need the first script (the localscript) please tell me in the answer section. Thanks!

1 Like

Does the player receive the cash after 60 seconds? Because if he does, it could be that the value does increase but doesn’t refresh.

it refreshes everytime it has changed (since I have a different script for the datastore)

1 Like

^ By using this, You get the Value once, You can modify it as much as you want, But it’ll never change.
Basically, What you’re doing, Is getting the Cash Value once, Therefore, The Value will remain the same. No matter how many times you modify it.
Try changing it to:

local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")

Now, You need to use .Value everytime you want to change the Value.

^ Change this to:

cash.Value = cash.Value - 50

And then you can do the same thing for the other ones, If you want to increment, Use +, Multiply *, etc.

2 Likes

oh ok thanks. (character limit)