Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm trying to make my leaderboard save my data but it doesn't work. can anybody help?

I'm trying to make my leaderboard save my data but i don't understand https://developer.roblox.com/articles/Saving-Player-Data so can someone help me or make a script for me? here is my code: local players = game:GetService("Players") local leaderboardData = game:GetService("DataStoreService"):GetDataStore("LeaderStats")

local button = script.Parent game.Players.PlayerAdded:Connect(function(player) local leader = Instance.new("Model", player) leader.Name = "leaderstats" local cash = Instance.new("IntValue", leader) cash.Name = "Cash" local crimelevel = Instance.new("IntValue", leader) crimelevel.Name = "Crime Level" crimelevel.Value = 0 end) the code is located in SeverScriptService.

8 comments

0

first, you create "players" and don't use it, second you create "leaderboardData" and never use it

0

The code is located in ServerScriptService but button is script.Parent?

0

it was first in a button so that why that is the parent

0

the players and leaderboard data was because i tried already but didn't work i will remove those.

0

this is the new code: https://ibb.co/SrtN7Jm

0

so does anybody know the answer?

0

i vollowed the wiki (copied the last script) and it still doesn't work:  https://ibb.co/ctQJtQ2     https://ibb.co/zrGfsVT     https://ibb.co/NtxcCYn

0

1 answer

You can use mine if you want.

local DataStore = game:GetService("DataStoreService"):GetDataStore("Something") 
-- In Something put a text like 'Coins' 'CoinSave' etc. it is up to you.
game.Players.PlayerAdded:Connect(function(player)

local key = "Coins_ID:"..player.UserId

local folder = Instance.new("Folder",player)

folder.Name = "leaderstats"

local coins = Instance.new("IntValue",folder)

coins.Name = "Coins"

coins.Value = 0

local save = DataStore:GetAsync(key)

if save then

coins.Value = save

end

repeat

DataStore:SetAsync(key,coins.Value)

wait(5)

until game.Players.PlayerRemoving

game.Players.PlayerRemoving:Connect(function()

DataStore:SetAsync(key,coins.Value)

end)

end)

I use this and it will create a leaderboard, and save it every 5 seconds![and when a player is leaving]

10 comments

0

thanks i will test it, if it doesn't work my roblox studio is bugged. thanks :)

0

i used your script and it still doesn't work. https://ibb.co/yYcsjcX does my game (i tested it on roblox) have to be in public?

0

it has to be in serverScriptService

0

ok

0

now the leaderboard(s) don't show up

0

no it doesn't have to be public, and try using a 'Script' in ServerScriptService. Also have you changed any of these scripts? And if there is an error in the output, try using warn() or print() to find which part is the error

0

Ok dont ask how but this is what i got, it is in serverscriptservice and the leaderboards show up its probably something i missed but it doesn't save the stats,

0

IK difrent stats then before, its for another game i am working on if i can just figure this out i can change it for the other one. P.S. yes i have 3 stats

0

check your player folder and see if there are multiple 'leaderstats' folder. Only needs one, and if you want to make more just make more inside the folder.

This discussion is preserved as it was. New answers, comments, and votes are closed.