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

1 answer

Log in to vote
0
Answered by 5 years ago

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]

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