Having trouble wit a data store + leader stats script. New to this, what am I doing wrong?
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Stats")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local stats = Instance.new("StringValue")
stats.Value = DataStore:GetAsync(Player.UserId) or 0
stats.Name = "Points"
stats.Parent = leaderstats
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.stats.Value)
end)
print("Community Leaderboard script loaded")
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "Points"
local mins = Instance.new("IntValue")
mins.Name = "Points"
mins.Value = 0
mins.Parent = stats
stats.Parent = newPlayer
while true do
wait(60)
mins.Value = mins.Value + 10
end
end
game.Players.ChildAdded:connect(onPlayerEntered)