Tool shop with tool saving

So, I’m trying to make a shop where players can buy weapons and get a option to equip the weapon and then the weapon saves when equipped, so when the player joins the game again the weapon he equipped before will be equipped when joining back.

Also I would want all the previously bought weapons to save and have the equip option so the players can go back and equip those at anytime.

I don’t need any scripts written for me I just want to know a step by step on how I would go about making this.

3 Likes

use datastore, its basically storing data, you could use it to store the weapons data heres a tutorial video by suphi kaner:

(https://youtu.be/B446FyN1xtc?si=06uXl5d1g51yNqWQ)

2 Likes

Heres another datastore tutorial by
GnomeCode:

(https://youtu.be/H-cDbjd5-bs?si=swuE_lFYf67Vstlz)

5 Likes

Just replying to point out, please use the Gnomecode one. He explains the best in most cases.

4 Likes

yeah, I know how to use datastore, so would I just use datastore also for saving previous weapons that were bought and saving the current weapon equipped?

1 Like

You can use strings to list the item name as a table, and have any stats it has inside of that table. Here is an example.

--pretend your datastore stuff is here
     ["Knife"] = {10, 5, 2}, -- format would be like damage, range, delay or something idk how you wrote it 

Then, once the player rejoins just do the opposite(get the weapon name from the list of weapons, apply the stats from in it and then put it in their inventory)

yes he does explain it easier and most of the time suphis tutorial are for intermediate users

1 Like

And there are many ways to store your data, if you can have multiple of each weapon you better make it like this:

local Data = {
    Weapons = {
        {
            1, -- Identifyer for e.g. "Knife"
            10, -- Damage
            5, -- Range
            1, -- Delay
            148, -- Uses left
        },
    };
}

Or if all weapons have set values and you don’t want to store stuff like “uses left”, you can store the Damage, Range and Delay in a separate table

local WeaponInfo = {
    [1] = {
        Name = "Knife";
        Damage = 10;
        Range = 5;
        Delay = 2;
    },
    [2] = {
        Name = "Sword";
        Damage = 20;
        Range = 10;
        Delay = 4;
    },
    [6] = {
        Name = "Grenade";
        Damage = 200;
        Range = 30;
        Delay = 20;
    },
    [7] = {
        Name = "Gun";
        Damage = 5;
        Range = 50;
        Delay = 1.5;
    },
}
local Data = {
    Weapons = {
        1, -- Identifyer for e.g. "Knife"
        2, -- Identifyer for e.g. "Sword"
        2, -- Identifyer for e.g. "Sword"
        7, -- Identifyer for e.g. "Gun"
        1, -- Identifyer for e.g. "Knife"
        6, -- Identifyer for e.g. "Grenade"
        2, -- Identifyer for e.g. "Sword"
        1, -- Identifyer for e.g. "Knife"
        1, -- Identifyer for e.g. "Knife"
    };
}

Next to that there are different ways to store data too, like if you have consumable items you are able to collect a lot of, it’s better to store these as a dictionary in your data:

local FoodInfo = {
    A = {
        Name = "Apple";
        HungerPoints = 5;
    },
    B = {
        Name = "Banana";
        HungerPoints = 10;
    },
    P = {
        Name = "Pear";
        HungerPoints = 8;
    },
    M = {
        Name = "Melon";
        HungerPoints = 25;
    },
}
local Data = {
    Food = {
        A = 1235; -- 1235 Apples
        B = 186; -- 186 Bananas
        M = 24; -- 24 Melons
        P = 72; -- 72 Pears
    };
}

There are way more ways to store your data, but make sure it:

  • Holds all data you need.
  • Holds as least as possible duplicate data.
  • Doesn’t take up unnecessary space
  • Is future proof, in case you want to adjust things in the future.

Edit:
A great practise is deserialisation after the initial get request and serialisation before any save requests.