What are Cars folder for? Is it a collection of all cars found?
These are just values so my barn find script can save what cars and barns the player does or dosent have, Basically i can look through and check for what barns the player has found and what cars the player has goten from the barns
local BFC = require(game.ServerScriptService.BarnFindConfig)
game.Players.PlayerAdded:Connect(function(Plr)
Plr:WaitForChild("InvisStats")
local BFA = {}
local BCA = {}
local Cont = false
for i,v in pairs(Plr.InvisStats.Barns:GetChildren()) do
if v.Value == false then
Cont = true
local CV = nil
for I,V in pairs(BFC.BarnFinds.Barns) do
if V.Value == v.Name then
CV = V
break
end
end
table.insert(BFA, CV)
end
end
for i,v in pairs(Plr.InvisStats.Cars:GetChildren()) do
if v.Value == false then
Cont = true
local CV = nil
for I,V in pairs(BFC.BarnFinds.Cars) do
if V.Value == v.Name then
CV = V
break
end
end
table.insert(BCA, CV)
end
end
print(BFA, BCA)
if Cont then
local BarnFindStarted = Plr.InvisStats.BarnFindStarted
repeat
local Barn = BFA[math.random(1, #BFA)].Model
local Cars = BCA[math.random(1, #BCA)].Key
if BarnFindStarted.Value == false then
BarnFindStarted.Value = true
Barn.Color = Color3.fromRGB(255, 0, 0)
Barn.Touched:Connect(function(H)
if H.Parent == Plr.Character then
BarnFindStarted.Value = false
Barn.Color = Color3.fromRGB(163, 162, 165)
local Car = Cars:Clone()
Car.Parent = Plr.Backpack
end
end)
end
BarnFindStarted.Changed:Wait()
until #BFA == 0 and #BCA == 0
end
end)
in the process of writing this
Why not structure your whole data like this
local AllCarsDiscovered = {
CarName = BarnName -- CarFound = BarnFoundIn
}
You obviously need to store all possible cars, if not AllCarsDiscovered[carName]
then you know the car hasnt been found, same applies with barns
The barn and car have no corilation, its compleately random what car is in what barn
Doesn’t prevent you from storing the car and barn found
Also the problem is i need to save these so the player doesent have to colect them again when they rejoin
I see what you mean now but thats ig what i cant do, to my knowlage you have to have values to save in order to save data and im just not sure how to do that on a mass scale
btw this might be a better structure
local carsFound = {
barnName = {"carnName1", "carName5"} -- or you can do ids if you have
}
You’ll have to use the DataStoreService to keep Data between playtimes. I reccomend doing as xHeptc said & store the values in a table so you can utilize a DataStore. Value instances will only last the session until the player leaves the game. You could structure your table so it looks something like this,
local Cars = {
["Car1"] = {["Found"] = true;};
["Car2"] = {["Found"] = true;};
["Car3"] = {["Found"] = true;};
["Car4"] = {["Found"] = true;};
}
local Barns = {
["RedBarn"] = {["Found"] = true;};
["GreenBarn"] = {["Found"] = false;};
["BlueBarn"] = {["Found"] = false;};
["YellowBarn"] = {["Found"] = false;};
}
Do you mean to save using the Roblox data services or just to organize it within your own game?
[edit] Nvm, I see now, you mean data services.
Easiest way is with string building encoding and decoding functions.
If its just to store whether its found, its better to just store array of barn and car names instead of dictionary and array
So from here should i package into a string like knightmb said?
why would you decode and encode when you can just save barn and carnames or their ids?
Are you familiar with the DataStore Service at all?
serialization and deserialization are for values such as cframe, color values, etc
for ex: Color3.new(0, 0, 0)
would be serialized to Color3.new(0, 0, 0):toHEX()
since hex is a string
Yes, unless he intends on adding more properties to each item which I imagine is a very real possibility
I don’t really understand the context of what you’re trying to do, but if you made various cars that look different you could store the id of the car (either the name, or number the different savable objects, but they must all be different). But if you want the player to maybe customize some of the properties of the car, then you should save those changes as well with the id.
Here is a script I made that will encode and decode an id, cframe, and 3 color3 values.
local DataStoreData = {
{100, {49.380001068115234, 0.5000038146972656, -118.16000366210938, 0.23391327261924744, -0.6097282767295837, 0.1356094628572464}, "1592ff","1592ff","1592ff"},
{100, {40.380001068115234, 0.5000038146972656, -118.16000366210938, 0.23391327261924744, -0.6097282767295837, 0.1356094628572464}, "1592ff","1592ff","1592ff"},
{100, {30.380001068115234, 0.5000038146972656, -118.16000366210938, 0.23391327261924744, -0.6097282767295837, 0.1356094628572464}, "1592ff","1592ff","1592ff"},
{100, {58.380001068115234, 0.5000038146972656, -118.16000366210938, 0.23391327261924744, -0.6097282767295837, 0.1356094628572464}, "1592ff","1592ff","1592ff"},
}
-- here the player has 4 cars of id 100
-- there are also 1 CFrame and 3 colors for each car stored
-- the CFrame is stored as position and :ToEulerAnglesXYZ()
local function DecodeData(DataStoreData)
local Data = {}
for index,object in pairs(DataStoreData) do
local t = {object[1]}
Data[index] = t
for i=2,#object do
local prop = object[i]
if i==2 then
t[i] = CFrame.new(prop[1], prop[2], prop[3])
* CFrame.fromEulerAnglesXYZ(prop[4], prop[5], prop[6])
elseif i>=3 and i<=5 then
t[i] = Color3.fromHex(object[i])
end
end
end
return Data
end
local function EncodeData(Data)
local DataStoreData = {}
for index,object in pairs(Data) do
local t = {object[1]}
DataStoreData[index] = t
for i=2,#object do
local prop = object[i]
if i==2 then
t[i] = {prop.X, prop.Y, prop.Z, prop:ToEulerAnglesXYZ()}
elseif i>=3 and i<=5 then
t[i] = prop:ToHex()
end
end
end
return DataStoreData
end
local Data = DecodeData(DataStoreData)
local ReEnc = EncodeData(Data)
print(DataStoreData)
print(Data)
print(ReEnc)
local comp_table
comp_table = function(table_1, table_2)
for i,v in pairs(table_1) do
if type(v)=="table" then
return comp_table(v, table_2[i])
elseif v~=table_2[i] then
return false
end
end
return true
end
print("same table = "..tostring(DataStoreData==ReEnc)) -- same table?
print("deep clone = "..tostring(comp_table(DataStoreData, ReEnc))) -- but the tables are the same
print(game:GetService("HttpService"):JSONEncode(DataStoreData):len())
This is the printed out DataStoreData table:
This is the printed out Data table:
I also did a deep table check to see the decode of the encode would give the original table, which it did.
When you go to save the encoded data, it will automatically convert the table to a JSON string if it is not already a string.
The string length limit is 4,194,304 per key-value entry.
The string length of the JSON encoded string is 609 characters in my example.
Thus you could have 27,548 cars with a CFrame and 3 colors and id=100
Higher ids would increase the length of the encoded data.
To answer the title of your question, “Is There An Easier Way To Store Obsesive Amounds Of Data?”
Using more key-values will increase the amount of data you can save.
The size limit is 4 MB, the throughput limit of each key is 25 MB and 4 MB per minute for read and write respectively.
There are request limits as well that limit how much data you can get at a time.
After going down a 4 day rabbit hole of how to compress data, I now recommend looking into this post:
The buffer library is news to me lol.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.