Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
sbot50 3
6 years ago

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.

0
first, you create "players" and don't use it, second you create "leaderboardData" and never use it greatneil80 2647 — 6y
0
The code is located in ServerScriptService but `button` is script.Parent? Vulkarin 581 — 6y
0
it was first in a button so that why that is the parent sbot50 3 — 6y
0
the players and leaderboard data was because i tried already but didn't work i will remove those. sbot50 3 — 6y
View all comments (4 more)
0
this is the new code: https://ibb.co/SrtN7Jm sbot50 3 — 6y
0
so does anybody know the answer? sbot50 3 — 6y
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 sbot50 3 — 6y
0
new new code: https://pastebin.com/dJtSHcsr sbot50 3 — 5y

1 answer

Log in to vote
0
Answered by 6 years ago

You can use mine if you want.

01local DataStore = game:GetService("DataStoreService"):GetDataStore("Something")
02-- In Something put a text like 'Coins' 'CoinSave' etc. it is up to you.
03game.Players.PlayerAdded:Connect(function(player)
04 
05local key = "Coins_ID:"..player.UserId
06 
07local folder = Instance.new("Folder",player)
08 
09folder.Name = "leaderstats"
10 
11local coins = Instance.new("IntValue",folder)
12 
13coins.Name = "Coins"
14 
15coins.Value = 0
16 
17local save = DataStore:GetAsync(key)
18 
19if save then
20 
21coins.Value = save
22 
23end
24 
25repeat
26 
27DataStore:SetAsync(key,coins.Value)
28 
29wait(5)
30 
31until game.Players.PlayerRemoving
32 
33game.Players.PlayerRemoving:Connect(function()
34 
35DataStore:SetAsync(key,coins.Value)
36 
37end)
38 
39end)

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

0
thanks i will test it, if it doesn't work my roblox studio is bugged. thanks :) sbot50 3 — 6y
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? sbot50 3 — 6y
0
it has to be in serverScriptService tree_tree00 48 — 6y
0
ok sbot50 3 — 6y
View all comments (6 more)
0
now the leaderboard(s) don't show up sbot50 3 — 6y
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 tree_tree00 48 — 6y
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, sbot50 3 — 5y
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 sbot50 3 — 5y
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. tree_tree00 48 — 5y
Ad

Answer this question