Hi,
Database isn’t working as you just read at the title and (checked several times) I don’t see anything I could’ve done wrong.
I tried printing some information out and it seems to go fine. Console shows ‘Data successfully loaded’ and ‘Data successfully saved’ messages but it doesn’t actually load/save pretty much.
Noticed that the error is probably when saving (Players.PlayerRemoved:Connect)
Note: I know leaderstats don’t work that way just let me be happy D:
Code:
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local DSS = game:GetService("DataStoreService")
local Database = DSS:GetDataStore("Database")
Players.PlayerAdded:Connect(function(player)
local Leaderstats = script.leaderstats:Clone()
Leaderstats.Parent = player
local Data
local Sucess, ErrorMSG = pcall(function()
Data = Database:GetAsync(player.UserId)
end)
if Sucess then
if Data == nil then
print("There is no data related to ".. player.DisplayName .." (@".. player.Name .."). Defaults will automatically be loaded.")
else
for i, v in pairs (Data) do
print(i, v)
end
print(player.DisplayName.." (@".. player.Name ..")'s data successfully loaded!")
Leaderstats.gems.Value = Data.Gems
Leaderstats.coins.Value = Data.Coins
Leaderstats.lvl.Value = Data.Level
Leaderstats.exp.Value = Data.Experience
Leaderstats.exp.limit.Value = Data.EXPLimit
Leaderstats.rewards.timeReward.Value = Data.TimeReward
Leaderstats.rewards.tournament.Value = Data.Tournament
Leaderstats.rewards.tournament.code.Value = Data.TournamentCode
Leaderstats.rewards.codes.beta.Value = Data.CodeBETA
Leaderstats.avatars.snowman.Value = Data.Snowman
Leaderstats.avatars.bunny.Value = Data.Bunny
Leaderstats.avatars.chicken.Value = Data.Chicken
Leaderstats.avatars.shark.Value = Data.Shark
Leaderstats.avatars.seal.Value = Data.Seal
Leaderstats.avatars.wolf.Value = Data.Wolf
Leaderstats.avatars.duck.Value = Data.Duck
Leaderstats.avatars.fish.Value = Data.Fish
player.Team = Teams:WaitForChild(Data.Checkpoint)
end
else
print("An error occurred while loading ".. player.DisplayName .." (@".. player.Name ..")'s data.")
warn(ErrorMSG)
end
end)
Players.PlayerRemoving:Connect(function(player)
local Leaderstats = player:WaitForChild("leaderstats")
print(Leaderstats.Parent.Name)
print(Leaderstats.gems.Value, Leaderstats.coins.Value)
local Data = {
Gems = Leaderstats.gems.Value,
Coins = Leaderstats.coins.Value,
Level = Leaderstats.lvl.Value,
Experience = Leaderstats.exp.Value,
EXPLimit = Leaderstats.exp.limit.Value,
TimeReward = Leaderstats.rewards.timeReward.Value,
Tournament = Leaderstats.rewards.tournament.Value,
TournamentCode = Leaderstats.rewards.tournament.code.Value,
CodeBETA = Leaderstats.rewards.codes.beta.Value,
Snowman = Leaderstats.avatars.snowman.Value,
Bunny = Leaderstats.avatars.bunny.Value,
Chicken = Leaderstats.avatars.chicken.Value,
Shark = Leaderstats.avatars.shark.Value,
Seal = Leaderstats.avatars.seal.Value,
Wolf = Leaderstats.avatars.wolf.Value,
Duck = Leaderstats.avatars.duck.Value,
Fish = Leaderstats.avatars.fish.Value,
Checkpoint = player.Team.Name,
}
local Sucess, ErrorMSG = pcall(function()
Data = Database:SetAsync(player.UserId, Data)
end)
if Sucess then
print(player.Name.."'s data successfully saved!")
else
print("An error occurred while saving ".. player.DisplayName .." (@".. player.Name ..")'s data.")
warn(ErrorMSG)
end
end)