I'm not the most experienced with data store, so something was bound to be wrong, but then when i had issues i looked at a datastore tutorial to find my mistakes () and it seemed like nothing was wrong. Here is the script:
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder",plr)
stats.Name = "leaderstats"
local Level = Instance.new("IntValue",stats)
Level.Name = "Level"
Level.Value = 0
local Tix = Instance.new("IntValue",stats)
Tix.Name = "Tix"
Tix.Value = 0
print("Hello , "..plr.Name)
local UsrId = "Player_".. plr.UserId
local data
local success, errormsg = pcall(function()
local data = DataStore:GetAsync(UsrId)
end)
if success then
Tix.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local UsrId = "Player_".. plr.UserId
local data = plr.leaderstats.Tix.Value
local success, errormsg = pcall(function()
DataStore:SetAsync(UsrId, data)
end)
if success then
print("Data saved")
else
print("Data not saved")
warn(errormsg)
end
end)
