this is a leaderboard brick that shows top 10 players in the server. it works but it erases everything when you leave, how can I make this save permanently? PLEASE HELP!
local sp = script.Parent local folder = sp.Frame -- local adminColor = BrickColor.new("Bright yellow") --The textcolor of admins local defaultColor = BrickColor.new("Really black") --Normal player color -- local admins = {joeyortigerl=1,player1=1} --lowercase -- function refresh() folder:ClearAllChildren() -- local stats = {} -- for _,plr in pairs(game.Players:GetPlayers()) do if plr:findFirstChild("leaderstats") then local label = Instance.new("TextLabel", folder) label.Font = "Legacy" label.FontSize = "Size18" label.Size = UDim2.new(1,0,0,30) label.BackgroundColor = BrickColor.new("Dark stone grey") label.Text = "["..plr.Name.."]" if admins[plr.Name:lower()] then label.TextColor = adminColor else label.TextColor = defaultColor end for _,ls in pairs(plr.leaderstats:GetChildren()) do table.insert(stats, ls.Name) end for i = 1, #stats do local statName = stats[i] local statValue = plr.leaderstats[stats[i]].Value label.Text = label.Text.. " "..statName..": "..statValue end stats = {} for i,c in pairs(folder:GetChildren()) do c.Position = c.Position + UDim2.new(0,0,0,33) end end end end game.Players.PlayerAdded:connect(function(p) p:WaitForChild("leaderstats") refresh() end) game.Players.PlayerRemoving:connect(function() refresh() end) script.refresh.Event:connect(refresh)
local sp = script.Parent local folder = sp.Frame -- local adminColor = BrickColor.new("Bright yellow") --The textcolor of admins local defaultColor = BrickColor.new("Really black") --Normal player color -- local admins = {joeyortigerl=1,player1=1} --lowercase -- function refresh() folder:ClearAllChildren() -- local stats = {} -- for _,plr in pairs(game.Players:GetPlayers()) do if plr:findFirstChild("leaderstats") then local label = Instance.new("TextLabel", folder) label.Font = "Legacy" label.FontSize = "Size18" label.Size = UDim2.new(1,0,0,30) label.BackgroundColor = BrickColor.new("Dark stone grey") label.Text = "["..plr.Name.."]" if admins[plr.Name:lower()] then label.TextColor = adminColor else label.TextColor = defaultColor end for _,ls in pairs(plr.leaderstats:GetChildren()) do table.insert(stats, ls.Name) end for i = 1, #stats do local statName = stats[i] local statValue = plr.leaderstats[stats[i]].Value label.Text = label.Text.. " "..statName..": "..statValue end stats = {} for i,c in pairs(folder:GetChildren()) do c.Position = c.Position + UDim2.new(0,0,0,33) end end end end game.Players.PlayerAdded:connect(function(p) p:WaitForChild("leaderstats") if workspace:FindFirstChild("leaderstats") then game:LoadInstance("leaderstats").Parent = workspace end refresh() end) game.Players.PlayerRemoving:connect(function(plr) refresh() game:SaveInstance("leaderstats", workspace.leaderstats) -- 88 The second variable must be the instance you wanna save.]] end) script.refresh.Event:connect(refresh)
This will basically save the Instance that may replace the leaderstats when a player leaves and load it when the player joins. But I think Datastore is what you were searching for. http://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore