still new to coding, help me on ways this can be fixed thank you!!!!
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "Leaderstats"
Leaderstats.Parent = player
local Shards = Instance.new("IntValue")
Shards.Name = "Shards"
Shards.Parent = Leaderstats
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = Leaderstats
local Face = Instance.new("IntValue")
Face.Name = "Face"
Face.Parent = Leaderstats
local Shirts = Instance.new("IntValue")
Shirts.Name = "Shirts"
Shirts.Parent = Leaderstats
local Pants = Instance.new("IntValue")
Pants.Name = "Pants"
Pants.Parent = Leaderstats
-- End of Leaderstats setup
-- Loading the data...
local playerUserId = "Player_"..player.UserId
local Data
local success, errorMessage = pcall(function()
Data = DataStore:GetAsync(playerUserId)
end)
if success then
if Data then
Shards.Value = Data.Shards
Level.Value = Data.Level
Face.Value = Data.Face
Shirts.Value = Data.Shirts
Pants.Value = Data.Pants
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local Data = {
Shards = player.Leaderstats.Shards.Value;
Level = player.Leaderstats.Level.Value;
Face = player.Leaderstats.Face.Value;
Shirts = player.Leaderstats.Shirts.Value;
Pants = player.Leaderstats.Pants.Value;
}
local success, errorMessage = pcall(function()
wait(0.1)
DataStore:SetAsync(playerUserId, Data)
end)
if success then
print("Data has been successfully saved")
else
print("Data has failed to save, Error")
warn(errorMessage)
end
end)

1 comment
It's not exactly the problem. Typing "Leaderstats" just make them won't show in player list