DataStore2 Weapons

Hello! I’ve searched all over the internet but haven’t found a solution yet…

How can I use DataStore2 to give players a default weapon once they join the game
and then their custom weapon once they change it

Any examples would be greatly appreciated :slight_smile:

I dunno how DataStore2 works, but I assume you at least know how to save with it.

I would use whatever function that makes it save, save whatever weapon the player has, and upon rejoin, give them that weapon.

Have it default to the default weapon, so it gives the default one if the player doesn’t have any other one.

Assuming it’s a tool, you could just clone() it into their backpack upon rejoin.

Hi, I suggest reading up on this. How to use DataStore2 - Data Store caching and data loss prevention

Here’s how you can give a player a default weapon with datastore2:

local datastore2 = require(path_ToModule);

local players = game:GetService("Players");

local function playerAdded(player)
    local playerData = datastore2("keyname", player);
   -- You can get a default table if you want to save, too.

   local defaultWeapon = playerData:Get(yourTool) -- This is will return the "yourTool"  if there's no data saved in playerData.

 --Here's how you get a default table;

   local default = playerData:Get({"Burger", "Pizza"}); -- This will return the table in the parameter if there's nothing saved in the datastore.



-- Here's how you can save in datastore;

playerData:Set(); -- You can save anything you want. (Correct me if I am wrong, you cannot save instances.)