my script doesn’t work, the script doesn’t recognise Player or Datastore
Enabled API services but the leaderboard still doesn’t appear. I am still learning some bits of scripting so if there are any wrong things I did please don’t hesitate to let me know.
script:
local Datastore = DataStoreService:GetDataStore("Wins")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wins = Instance.new("StringValue")
Wins.Name = "Wins"
Wins.Value = DataStore:GetAsync(player.UserId) or 0
Wins.Parent = leaderstats
end)
game.Players.PlayerRemoving:Connect(function(Player)
Datastore:SetAsync(Player.UserId, Player.leaderstats.Wins.Value)
end)
Capitalisation really matters, especially with variables.
FYI: You should be pcalling those Datastore methods, they have a high tendancy to error and Players can lose data due to it. Here’s a good tutorial by ReturnedTrue (whoever that is) on pcalls: