Sure. You might not want to save raw names though since that’ll eat up the character limit you have for a DataStore key (260K characters) and instead opt for condensing your data by using numbers or other ids instead, but if you don’t have that many items then feel free to use raw names as well. Same goes with the Equipped table.
Yes, that’s what I’m essentially saying. My issues is how to do that, but some fellow developers have already pointed out data stores.
yes you can save bools strings but not objects i would recommend making a new string value of the item and then put it inside the players data folder and load the shirt based on the string values name
My plan was to simply save it as “Char1”, “Char2”, “Hat1”, “Hat2”, all as names of bool values, all representing items and their shop number, with true and false being whether or not they own it. From there I would also add “HatEq”, “CharEq”, etc. for what they have equipped, these would be number values, with the number correlating to the item number. Is this condensed enough to fit the limit?
One important question, when you say “between games” do you mean separate published games or gaming sessions inside a single game.
Currently both have been discussed.
I am referring to gaming sessions. Although, within the same game there are 2 different places. There is a singleplayer place, and a multiplayer place. Would this be an issue to transfer over from the data storage?
No, DataStores will be accessible from every place inside your game.
and you could condense your info to a bit string with each digit corresponding to a specific item in catalog (1 for yes, owned. 0 for no)
You can hardcode the relationship and asset id’s, all you need is if the player owns it saved.
Unless your catalog is so large that a bit per item is larger than your average players collection
You can learn how to use DataStore to saving items in table, create a folder in the player name “EquippedChar” , also when player join a game, there will be a script that check their equipped character and then module their, else if player not have any equipped char, then it will module and give them an default character.
Here is the best choice for you if you want to learn how to saving items in table!
Yeah. I was going to add a playerAdded, and then in there a characterAdded, and detect what they have saved. Would there be a way to detect what they have equipped though? I have toros colors, materials, hats, and heads, so I’m assuming I would just add 4 digits to the end and the number would be the “ID” of the item within the game?
Thanks! And I will check out the link. One thing though, can’t the player configure values and items that are within the player? If so, then this would allow exploiters free-range to equip any item they please.
the bit string is just for ownership
Equipped items you would want references to the actual item. perhaps a number (5) which is a specific hat (whose ownership is the fifth digit)
Each equipped item would have its own saved variable, but the set would never exceed the size of max # of items one is able to equip.
so:
ownershipBits = “…”
hat = 5
character = 19
socks = 190
leftEarring = 201942 ?
–hehe
Oh okay, I see! Is there a way to check specific digits within a string? For instance, the game is checking if you own “Domino Crown”, and Domino Crown’s digit within the string will be 4. So how would you configure the digit upon leave to show that domino crown is bought, and then upon rejoin check the digit to see if it is owned?
To more security, you can move your CustomCharacter and items into “ServerStorage”, so the exploiters can’t access it, the ServerStorage is a game Storage that only can be access within an Server Script, so they can’t access it because their exploits only work at a LocalScript! Anyway, you can learn how to use “RemoteEvent” and “RemoteFunction” to prevent it and one thing through, exploiters can still configure it BUT they only see that on their client, so the player on another client can’t see it! That mean you don’t need to worry about that, make sure focus on Remote in some important things ( Char, Items, Guns, Fire and Reloading, etc…) so your game will be security!
How large is your set?
Roblox now has a bit32 library now.
This is manipulating an actual bit though.
local bitStr = 1 --its a one
print(bit32.extract(bitStr,0,1)) -- prints 1
print(bit32.extract(bitStr,1,1)) -- prints 0
bitStr = bit32.replace(bitStr,1,1,1) -- made that 0 a 1
--side note documentation for ^ is missing v argument in function definition
print(bitStr) -- it is now 3, because 11 in binary is 11
This you are manipulating a number, one bit at a time. Your info is from right to left, because numbers.
Data position refers to the exponent of digit.
position 0 is 2^0 place
position 12 is 2^12 place
You can just use a real string and just put 0’s and 1’s as pseudo bits. I doubt you will reach the limit.
local ha = "happy helper" --random string
print(ha)
local tablet = table.pack(string.byte(ha,1,-1)) --converts to numerical value each char
print(tablet) -- its a table reference
local he = string.char(table.unpack(tablet)) --pokes back into string
print(he)
-- 48 is '0' and 49 is '1'
You would take and manipulate the table, it is sequential so each bit has an index = digit place (y is tablet[5])
This is much more intuitive (left to right).
The way I would go about saving the characters and bucks is I would create a folder within the player called “Characters”, and in it is a load of bool values, with the same name as each character.
Then, you make it so when a certain character is equipped, the game checks the folder within the player and sets the value to true for whatever character they have equipped. For example, if you have a “Noob Character” equipped, the bool value within the character for noob will be set to true once its equipped, and all other values will be set to false.
After this, you can use datastores to save all of the values, and make it so when you rejoin, the values load as they were in the previous game session. So when you join, the datastore would load the data and it would check the folder within the player to see if a character is equipped and if one is it would set the players character to that character.
For saving bucks, assuming its just an IntValue within leaderstats, you can use this script, but it may need tweaking a bit. Heres what I would do to save bucks.
local bindableEvent = Instance.new("BindableEvent")
local playersLeft = 0
game.Players.PlayerRemoving:connect(function(player)
playersLeft = playersLeft - 1
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
print("saved data number "..i)
end
print("Stats successfully saved")
bindableEvent:Fire()
end)
game:BindToClose(function()
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)
game.Players.PlayerAdded:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local bucks = Instance.new("IntValue")
bucks.Name = "Bucks"
bucks.Value = 0
bucks.Parent = leaderstats
player:WaitForChild("leaderstats")
wait(1)
local stats = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
print("stat numbber "..i.." has been found")
end
end)
This script should go in ServerScriptService. If you use this you may need to change around some stuff, but for the most part it should work in saving data found in the leaderstats folder when the player leaves and loading it when the player joins. The playersLeft counter and the BindableEvent is used to make sure there are no players left before a server shuts down, to ensure data gets saved if someone leaves the game and a server becomes empty.
I hope this helped, you can edit the script to also save the characters in the way I stated above. If I’ve made any mistakes then I’d be grateful if someone corrected me.
I have actually used RemoteEvents and RemoteFunctions a lot in this game so far haha, I had just assumed you meant store the character in the player itself, which obviously isn’t good. The items are already stored in ReplicatedStorage, and from there you retrieve the item from there and set it on your character when you purchase it. but do you think ServerStorage would be a good idea?
My set is a total of 26 items, 8 torsos, 8 hats, 8 materials, and 2 heads. I don’t know if that really changes anything but it isn’t a multiple of 8, so perhaps?
Yes, but actually Local Script can’t access Server Storage so it would be more security because exploits only working like a Local Script, only Server Script can access it, it would be helpful to prevent hackers!
Smart idea! I’ll bring the hats to ServerStorage.
You can’t save data across game “universes” but you CAN across different places within the same game “universe”.
NOTICE: I previously mispleledand wrote can instead can’t for the following:
You can’t save data across game “universes”
Apologies for any confusion and thanks to @XxELECTROFUSIONxX for pointing it out!