Using module to help with skin datastore

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Skin datastore using a module that has the skin’s information

  1. What is the issue? Include screenshots / videos if possible!

I don’t know how to make a module that stores tables and save the data like if the skin is owned or isn’t.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried making the tables in the datastore script but it is insanely long and hard to identify which is which. It can’t have information like if it is owned or not, equipped or not.

3 Likes

It’s best if you store stuff like this using ID’s and not full strings.

you can have your module with the skin data structured as this:

return {
-- [id] = data
   [1] = {--[[whatever data you need **INGAME ONLY**]]}
}

Now; you want to store player data as something like this;

DataStoreData = {
   skins = {
       -- equipped, owned
      "1", "0,1,2,3,4,5"
   }
}

local playerOwnedSkins = string.split(DataStoreData.skins[2], ",")

You want to make sure you have a seperator incase you have ids longer than 1 character
To turn an array with owned id’s {0,1,2,3,4,5} into the string to save you just want to table.concat() it

How would you know if it’s owned because the numbers are confusing. I was thinking for each skin has data like owned = true or false and cost = number and equipped = true or false

1 Like

the numbers correspond to each skin
storing multiple tables with multiple indexes alongside the cost, which you do not need in the datatstore and also storing every skin’s information regardless of if you have it or not is a very big waste

-- ModuleScript, "SkinInfo"
return {
-- [id] = data
   [1] = {
      price = 10,
      name = "Idk",
   },
   [2] = {
      price = 15,
      name = "Idk2",
   },
}

Lets say you have this module,
You get the player’s stored data, which could be

local PlayerData = {skins = {
   "2", "1,2"
}}

To get the currently equipped skin, you do
local equippedSkin = PlayerData.skins[1]

To get an array of skins you unlocked, you do
local playerOwnedSkins = string.split(DataStoreData.skins[2], ",")

Theese are all id’s, to get the information like the price and name of them, you index the module with the ID

local SkinInfo = require(script.SkinInfo)

local equippedSkin = tonumber(PlayerData.skins[1])
local equippedSkinData = SkinInfo[equippedSkin]

print(equippedSkinData.price, equippedSkinData.name)

I have another problem. How would I save this as data so when the player loads it will fetch the data and apply the skin that was last equipped. I’m only familiar with saving values not tables.

saving a table is the same as saving other values

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.