How to use Datastore Service on my game?

Hello devs! so i want to use datastore on my game. in menu place, my script creates a “data” folder at player. i dont want it to reset, and also when in main game, i want the main game to get data from menu. how can i do that?

my script:

game.Players.PlayerAdded:Connect(function(plr)

local datafolder = Instance.new(“Folder”)
datafolder.Name = “Data”
datafolder.Parent = plr

local raceval = Instance.new(“StringValue”)
raceval.Name = “Race”
raceval.Value = “Human”
raceval.Parent = datafolder

local coinval = Instance.new(“IntValue”)
coinval.Name = “Coins”
coinval.Value = 30
coinval.Parent = datafolder

local dmgmltplr = Instance.new(“NumberValue”)
dmgmltplr.Name = “Damage”
dmgmltplr.Value = 1
dmgmltplr.Parent = datafolder

local fightingstyle = Instance.new(“StringValue”)
fightingstyle.Name = “Fighting Style”
fightingstyle.Value = “Human”
fightingstyle.Parent = datafolder

local fstool = game.ReplicatedStorage.Tools.FS[fightingstyle.Value]:Clone()
end)

end)

2 Likes

I’d strongly recommend you check out Data Stores | Documentation - Roblox Creator Hub, it contains everything you need to know to get started and includes helpful examples.
Small word of advice, please take note of ratelimits! They’re very easy to miss and you’ll regret not respecting them.

2 Likes

i tried to check it but i didnt really understood anything

1 Like

you need to use game:GetService(‘DataStoreService’)?

1 Like

Then you probably don’t have enough experience with scripting. I recommend you checking a tutorial and understanding whats happening.
Datastores can be easy to use but also very difficult, depends on the amount of data you need to store. Most people save every part of data into its own key (<playerId>/money), sometimes it’s enough.
However in bigger games, it is recommended to save all data into JSON under one key, but then there’s limit of 4MB and data can get too big easily, so a sharding must be introduced.

1 Like

I would strongly recommend profile service. It’s easy to use and abstracts a lot of potential issues you could face when using data store