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

Saving user leaderstats in game won't work, help?

Asked by 8 years ago

I'm completely new to using the save feature on Roblox. I realize this won't work because I'm trying to locate a local player using a regular script. This scripts parent is ServerScriptService. How do I successfully go about saving this type of user data?

local Leaderboard = game.Players.LocalPlayer:WaitForChild("leaderstats")

game.Players.PlayerRemoving:connect(function(plr)
local key = plr.UserId
game:GetService'DataStoreService':GetDataStore('Data'):SetAsync(key, plr.leaderstats.RankVal.Value)
end)

1 answer

Log in to vote
0
Answered by 8 years ago

First part of the script would error out and I think it may have affected the rest of the script from running. Not sure if that's 100% true or not. But other then that you hit the nail on the head. Also I recommend using a variable for the getting the datastore and the leaderstats. Just so when and if you need to use them in another function in the script you don't have to rewrite part of it.

Here's the part you want though ;)

local DS = game:GetService('DataStoreService'):GetDataStore('Data')
game.Players.PlayerRemoving:connect(function(plr)
    local key = plr.UserId
    local leaderboard = plr:WaitForChild('leaderstats')
    DS:SetAsync(key, leaderboard.RankVal.Value)
end)
Ad

Answer this question