How to add overall Stats support?

I want to add stats to my game like the one in Retail Tycoon 2 . It holds all the qualities you sold from each item in the game.

Here’s a picture

Screenshot

I wanted to ask you guys if there was a easier way to approach rather than having to create and datastore a whole new IntValue that would hold this information.

Thank you,
Madd

2 Likes

You could use one string value, to handle all of this; it’s a bit hacky, bit would work IMO.

local String = "Cake 1, CakeE 2, CakeF 3"
local TempTable = {}
local Result = {}

function csvToTable(List)
	for Line in String:gmatch("[^,]+") do
		TempTable[1+#TempTable] = Line
		print(Line)
	end
	print(TempTable)
	
	for _,Line in ipairs(TempTable) do
		local Index, Value = Line:match("(.*) (%d+)")
		print(Index)
		print(Value)
		Result[Index] = Value
	end
end

while true do
	wait(5)
	csvToTable(String)
	print(Result)
end

Here you effectively have a string Cake 1, CakeE 2, CakeF 3

The code will convert that into a table where the Cake name is the index, and the number is the value.

It’s one way you could do this avoiding a million intvalues.

1 Like

Would this datastore?

Also people would sell things in like the thousands so this method would not work the best.

so you can save tables in data stores right?

why dont you just save a table with varuables:

Data = {
first = first.Value;
second = second.Value;
third = third.Value;
}

and then when you will get that table you can do this thing:

first.Value = Data.first
second.Value = Data.second

and so on i can share some of my code with you if u want

2 Likes

alr go to the 22:29 on this vid he explains it, and btw it wasnt hard to find why would u go on a forum.

or you are saying that you want to pack all of these values into one string or wat

1 Like

I want to datasave this but like I don’t want 300 int values in my game

just use smth like astral did with the string although i think its just better to have a folder with a ton of values and just make some for loop to save them into data stores and also for changing these values u can make another for loop that will make a connection for every value in that folder

So you say go the int value route?

i just say it is easy and overall good enough so idk

1 Like

I was just trying not to have like 3,000 int values in my game.

woah why do you need that many??? Can you explain more… or did u mean about a 100

1 Like

So I need value for each of the products in my game you can own correct.

For example paper, markers etc… (Could easliy go up to about 100 maybe somewhere around 60 at the least.)

Then I also need cash, store names, etc…

As well as if I want stats for each value I need to double it so it calculates how much a player has sold of each.

Only if I go that route.

i dunno i have about 100 int values in my game per player and it works fine, for data saving just do smth like this:

local DataStorage = DataService:GetDataStore("Values")

Players.PlayerAdded:Connect(function(player)
local Values = game.ServerStorage.Values:Clone() --Folder with ur values
Values.Parent = player

local data
	local success, errormessage = pcall(function()
		data = DataStore:GetAsync(player.UserId.."-Values") --Gets that we saved
	end)
	
	if success and data then
		for i,v in pairs(Values:GetChildren()) do
          Values:FindFirstChild(i).Value = v --if it finds the data then to all values in a folder it gives a value bruh 
end
	else
		
	end)

Players.PlayerRemoving:Connect(function(Player)
local DataToSave = {}

for i,v in pairs(Player.Values:GetChildren())
DataToSave[v.Name] = v.Value --saves stuff idk

DataStore:SetAsync(player.UserId.."-Values", DataToSave)
end)

btw that rily raw code written in 5 min so yeah hope u get how that supposted to wokr

and what do you mean by “As well as if I want stats for each value I need to double it so it calculates how much a player has sold of each.” just each time player sells smth you find that smth in a folder and add a quanity of sold stuff to it

alr i will have a dinner rn

alr i had it so maybe you add me friends on roblox that just would be more practical than write to each other each like 12hrs uknow

1 Like

I do know how to data save

What does this mean?

[quote=“101010lilfanerka, post:13, topic:1753549”]
ch time player sells smth you find that smth in a folder and add a quanity of sold stuff to it
[/quote] well so as i understand each time a player sells smth in ur game you want to detect it and make a value go bigger right? So just make a connection that can do just that idk dud

wat do you even need at this point

I am sorry your English is not understandable what is ch, smth, dud.

IKR. So just tell me what are you trying to do and what is your problem. At first you wanted to do data saves without a lot of values now what?

I don’t think I ever asked for Datasaving help.

What I need is this.

There is a value called Paper in a game. In that game people buy paper. And sell paper. When people sell paper I want that to add all together to create a new value which would be sold paper.

My question is instead of making 2 leaderstat values one for regular paper and one for sold paper.

Is there an easier way?

Something I don’t know of?

alr so you want stats for bought paper and sold paper right?

1 Like