So I know already how to save and load stuff, tho I've come across a post that made me ask this -
which of the following will be better for saving hats?
Option A: have a Equipped boolvalue in each hat, and then simply save that value and the hat [as string with bool] ,and then when rejoin check the bool.. if equipped then add the hat on the player etc..]
Option B: have a dictionary for all players in game to handle the hats - so whenever they put a hat, it'll be added into their table , and when they unequip it, it's removed from the table, and simply just save their table strings and when they join, all hats in their table meaning they wore those hats before they left, so will seach for them in a folder 'hats' and then equip it on them etc
#Which way is better to do?
1 messages · Page 1 of 1 (latest)
--Option B thing
local playerHats = {
["Player1"] = {"Hat1","Hat2"},
["Player2"] = {"Hat2"},
["Player3"] = {} -- has no hats from the ones in game catalog equipped on him
}
--and then save each player's equipped hats table
by 'better' I mean- more efficient and effective
give me a min, I have a way you can do it effectively
[They'll also be able to customize faces and 'kits' [shirt+pants]], so will need to store these all
Here's a better way of doing this, it takes a little more manual work, but it takes alot less space in the data store.
local HatsIndex = {
[1] = "Top Hat",
[2] = "Bowler Hat",
[3] = "Crown"
}
local HatsDictionary = { -- You can write a simple loop to setup this table for you using HatsIndex, or visa versa so you don't have to write both out manually
["Top Hat"] = 1,
["Bowler Hat"] = 2,
["Crown"] = 3
}
local PlayerHats = {
["Player1"] = {1, 2}, -- Reference HatsIndex to get the hat from the number
["Player2"] = {2},
["Player3"] = {}
}
if you're doing this, you'll probably need tables for each clothing type and Indexes/Dictionaries to go along with them
Hell in studio
are you grabbing items from the roblox catalog or making your own?
for index,hat in pairs(game.ServerStorage.Hats:GetChildren()) do
HatsIndex[index] = hat
end
for index,hat in pairs(game.ServerStorage.Hats:GetChildren()) do
HatsDictionary = index
end
Well, I think I might use catalog ones
then use their asset ids
but maybe use ones from not the catalog too
I know, but since I might have non-catalog items too..
ok, so save catalog ones like this "12345678" (just asset id as a string, no need for a dictionary because it's a roblox accessory), and your custom ones like this "_123" with some sort of prefix or suffix so you can know it's a custom one and look up in a dictionary/index like in the examples I showed you
tho why need the first 2 ones ,couldnt they be only 1?
you'll need both so you can convert between number and name freely, but one can be setup with code using the other
so you only need to type one out manually, and then you can write a loop to create the other
local HatsIndex = {
[1] = 7602467680,
[2] = 4681589621,
[3] = "CustomHat1" -- custom hats will be in a folder in serverStorage[ or should I save them as a model and then load it using the model ID?
}
local HatsDictionary = {
}
for index,value in pairs(HatsIndex) do
HatsDictionary[value] = index
end
local PlayerHats = {
["Player1"] = {1, 2},
["Player2"] = {2},
["Player3"] = {}
}
so like catalog items could simply just have their assetID's, and custom ones could be saved as models and then load the accessory/clothing from them using insertService ?
If so, it'd make it even easier to apply the custom ones using insertService
thing is I might need to add a 'Image' value for the custom ones
Well you can use the name for custom ones if you want, it would make it easier for you
And you don’t need the index if your gonna use asset ids, just save the asset ids directly
You can make a dictionary for that