Hey. Thanks for Clicking :) So, my next game uses a Datastore to save the Player's Leaderstats. I have two problems with this. 1) When the player wins a game, a win is not added to the leaderboard. 2) I dont know if it stores or loads their data, because there is never anything to store. I'll post that anyway. Here's the script that is supposed to add a win.
function awardwin(players)
if type(players) == type({}) then
print("player is in table") -- this prints
for i = 1, #players do
if players[i]:FindFirstChild("MatchTag") then
if players[i]:FindFirstChild("leaderstats") then
if players[i].leaderstats:FindFirstChild("Wins") then
local stat = players[i].leaderstats.Wins
stat.Value = stat.Value + 1
print("added wins") -- this never fires
end
end
end
end
end
end
This is when the function is called in the main script.
while localtimer > 0 do
print("Run")
wait(1)
localtimer = localtimer - 1
activecontestants = {}
for _, player in pairs(contestants) do
if player then
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
local matchtag = character:FindFirstChild("MatchTag")
if matchtag and humanoid and humanoid.Health > 0 then
table.insert(activecontestants, player)
end
end
end
end
if #activecontestants <= 1 then
awardwin(players)
awardcredit(players, 4)
break
end
end
Finally, this is where the player's data is saved
game.Players.PlayerRemoving:connect(function(player)
local newTab = {}
local tab = myData:GetAsync(player.userId)
local num = 0
for i = 1,#tab do
num = num + 1
for a,b in pairs(player.leaderstats:GetChildren()) do
if b.Name == tab[i][1] then
table.insert(newTab,{tab[i][1],tab[i][2],tab[i][3]})
end
end
if num % 10 == 0 then
wait()
end
end
myData:SetAsync(player.userId,newTab)
end)
Thanks!
