Help with data store script

so, i’m making RPG game, I did leaderstats with data store,i watched every single tutorial on YouTube but none is working, can someone help me with this? (yes, I enabled Studio AIP services, here is script:
leaderstats:

local dataStore = game:GetService(“DataStoreService”)
local myDataStore = dataStore:GetDataStore(“MyDataStore”)

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

local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"

local Wind = Instance.new("IntValue", leaderstats)
Wind.Name = "Winds"

local Level = Instance.new("IntValue", leaderstats)
Level.Name = "Level"
Level.Value = 1

local Exp = Instance.new("NumberValue",player)
Exp.Name = "Exp"
Exp.Value = 0

local RequiredExp = Instance.new("NumberValue", player)
RequiredExp.Name = "RequiredExp"
RequiredExp.Value = Level.Value * 100

Exp.Changed:Connect(function(Changed)
	if Exp.Value >= RequiredExp.Value then
		Exp.Value = 0 
		Level.Value += 1
		RequiredExp.Value = Level.Value * 100
	end

end)
end)

datastore script:

local myDataStore = game:GetService(“DataStoreService”):GetDataStore(“MyDataStore”)
game.Players.PlayerAdded:Connect(function(player)
wait()
local playerId = “Id_”…player.UserId
local data1 = {player.leaderstats.Winds.Value,}
local data2 = {player.leaderstats.Exp.Value,}
local data3 = {player.leaderstats.Level.Value,}
local data4 = {player.leaderstats.RequiredEXp.Value,}
local Save = myDataStore:GetAsync(playerId)
if Save then
data1.Value = Save
else
local current = {
data1.Value,
data2.Value,
data3.Value,
data4.Value}
myDataStore:GetAsync(playerId, current)
end
end)

game.Players.PlayerRemoving:Connect(function(player)
myDataStore:SetAsync(“id_”…player.UserId,{
player.leaderstats.Winds.Value,
player.leaderstats.Level.Value,
player.leaderstats.Exp.Value,
player.leaderstats.RequiredExp.Value})
end)

Have you tested it on studio or in-game?

yes I did, I joined in Roblox studio didn’t worked, I joined in Roblox didn’t worked

Could you please format (```) your code better, so we can read it faster?

leaderstats:

(’’ game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”, player)
leaderstats.Name = “leaderstats”

local Wind = Instance.new(“IntValue”, leaderstats)
Wind.Name = “Winds”

local Level = Instance.new(“IntValue”, leaderstats)
Level.Name = “Level”
Level.Value = 1

local Exp = Instance.new(“NumberValue”,player)
Exp.Name = “Exp”
Exp.Value = 0

local RequiredExp = Instance.new(“NumberValue”, player)
RequiredExp.Name = “RequiredExp”
RequiredExp.Value = Level.Value * 100

Exp.Changed:Connect(function(Changed)
if Exp.Value >= RequiredExp.Value then
Exp.Value = 0
Level.Value += 1
RequiredExp.Value = Level.Value * 100
end

end)
end)’’)

I don’t know how to do (’’’’) format

datastore script:

local myDataStore = game:GetService(“DataStoreService”):GetDataStore(“MyDataStore”)
game.Players.PlayerAdded:Connect(function(player)
wait()
local playerId = “Id_”…player.UserId
local data1 = {player.leaderstats.Winds.Value,}
local data2 = {player.leaderstats.Exp.Value,}
local data3 = {player.leaderstats.Level.Value,}
local data4 = {player.leaderstats.RequiredEXp.Value,}
local Save = myDataStore:GetAsync(playerId)
if Save then
data1.Value = Save
else
local current = {
data1.Value,
data2.Value,
data3.Value,
data4.Value}
myDataStore:GetAsync(playerId, current)
end
end)

game.Players.PlayerRemoving:Connect(function(player)
myDataStore:SetAsync(“id_”…player.UserId,{
player.leaderstats.Winds.Value,
player.leaderstats.Level.Value,
player.leaderstats.Exp.Value,
player.leaderstats.RequiredExp.Value})
end)

Your setting one Async for all Values, but then setting one Value to All Values?

ohh, thanks, ima go go set async to all values

Do something like this:


local myDataStore = game:GetService(“DataStoreService”):GetDataStore(“MyDataStore”)
game.Players.PlayerAdded:Connect(function(player)
wait()
local playerId = "id_"..player.UserId
local data1 = player.leaderstats.Winds.Value
local data2 = player.leaderstats.Exp.Value
local data3 = player.leaderstats.Level.Value
local data4 = player.leaderstats.RequiredEXp.Value

local Save = myDataStore:GetAsync(playerId)
if Save then
data1.Value = Save[1]
data2.Value = Save[2]
data3.Value = Save[3]
data4.Value = Save[4]
else
local current = {
data1.Value,
data2.Value,
data3.Value,
data4.Value}
end
end)

game.Players.PlayerRemoving:Connect(function(player)
myDataStore:SetAsync("id_"..player.UserId,{
player.leaderstats.Winds.Value,
player.leaderstats.Level.Value,
player.leaderstats.Exp.Value,
player.leaderstats.RequiredExp.Value})
end)

didn’t worked for some reason, there is no errors in input or script analysis

Could you say if the script above works?
I just edited it, so please try again if you already checked it.