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

Player data for "leaderstats" won't save on my world, anyone know a fix?

Asked by 5 years ago
01local DSServ = game:GetService("DataStoreService")
02local plrServ = DSServ:GetDataStore("PlrLeaderboard")
03 
04game.Players.PlayerAdded:Connect(function(client)
05    local leaderstats = Instance.new("Folder")
06    leaderstats.Name = "leaderstats"
07    leaderstats.Parent = client
08 
09    local cash = Instance.new("IntValue")
10    cash.Name = "Cash"
11    cash.Parent = leaderstats
12 
13end)
14 
15game.Players.PlayerRemoving:Connect(function(client)
View all 31 lines...

This may seem like a lot, but I'm just trying to save player data to set up a currency system for a game (the world has API for Studio turned on). I made a mechanic that adds 1000 to my currency whenever I leave the game (it checks for my UserId and adds it if the current player's Id and mine match, meaning it's me). I don't know what the problem is, but it won't save the data. Please let me know what the problem is if you think you know. Thx

0
Maybe you don't load it once you join? Robloxian_Hero1234 14 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
01local DataStore = game:GetService("DataStoreService")
02local CashData = DataStore:GetOrderedDataStore("Cash")
03 
04game.Players.PlayerAdded:Connect(function(plr)
05    local Cash = CashData:GetAsync(plr.UserId)
06    local leaderstats = Instance.new("Folder")
07    leaderstats.Name = "leaderstats"
08    local CashValue = Instance.new("IntValue", leaderstats)
09    CashValue.Value = Cash
10    leaderstats.Parent = plr
11    CashValue.Name = "Cash"
12 
13end)
14 
15game.Players.PlayerRemoving:Connect(function(plr)
16    local Cash = plr.leaderstats.Cash.Value
17    CashData:SetAsync(plr.UserId,Cash)
18    print("Saved data")
19end)

--you can change anything called Cash to your currency

0
on line 8, what does the 2nd parameter do? User#28017 0 — 5y
0
Thanks, the script worked! Btw could you explain how this all works. Do it only if you want to, just wanting to know that I understand what the code is doing. User#28017 0 — 5y
0
Line 8 is just for me. It for a different script. Forgot to take that out GunzerkingBeast21 -4 — 5y
Ad

Answer this question