How do I make a Currency System for my Game?

Hello.

I am currently working on a first-person Roblox horror game called Classrooms that has two full on currency systems, Credits and Diamonds. Credits is the primary currency and Diamonds is the secondary currency. I am trying to make a demo for the Credits value to rapidly increase (a test to see if the currency system works) and it doesn’t seem to work. I also want to make it work on the player’s client, not all clients.

Here is my code if you need it:

local Credits = script.Parent.Credits_Value.Value
local CountCredits = script.Parent.Parent:WaitForChild("Credits_Counter").Text

while true do
	script.Parent.Text = Credits
	Credits = Credits + 1
	wait(0.01)
end

Please help me. It will help my game development process go by faster :).

is there any error? Where is the Credits variable? Please show more

Also I’d use profileservice for datastore, look into it as it will come in handy and will differ your approach as a whole.

There are no known errors in the output for this system. However there are a million errors for all the other scripts (dont comment about them :))
The Credits variable is “local Credits =.” I forgot to include it in the code sample :smiling_face_with_tear:

To do this you should run the code on a local script. What I recommend doing is dealing with the money giving stuff on the server but then using a remote event to fire the event to change the amount of credits someone has.

Another issue is that you are getting the value in the variable “Credits” however you overwriting the variable value meaning that you are not updating the “Credits_Value” value but rather just changing the variable value. To fix this just simply add .Value when you want to set the value rather then setting the variable to the stuff that is in the value.

Just some smaller points also:

  • You should be using the task library to add a wait in your code. So rather then using wait() it would be task.wait(). Just in general makes the wait more accurate and better.

  • You can just do += where you want to add a number onto another number because it gets the value and then add on the number u want.