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

How do i save Leaderstats?

Asked by 4 years ago

Hi, I am new here, and also to scripting. (Just go easy on me) so, I am making a game that has Points and Wins in Leaderstats;

game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local val = Instance.new("IntValue")
val.Name = "Points"
val.Value = 0
val.Parent = leaderstats
local val = Instance.new("IntValue")
val.Name = "Wins"
val.Value = 0
val.Parent = leaderstats
end)

But how do i Save my Leaderstats?

Thanks,

-kyan_BVBfan

0
There's 2 options. ROBLOX DataStore OR Kampfkarren DataStore2 | I recommend DataStore2 for values (Bools, Ints, Strings, ETC.) and ROBLOX DataStore for tables (JSON, Dictionaries, ETC.) There are plenty of tutorials on youtube and resources for both of the datastores. killerbrenden 1537 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Here's DataStore2 - In My Opinion, Better For Values

ServerScript Inside Of ServerScriptService

--// Gets DataStore2
local DataStore2 = require(1936396537)

--// Sets Key For Data
DataStore2.Combine("_GAME_DATA_","Points","Wins") --// You Can Change "_GAME_DATA_" To Anything And It'll Reset All Values For Every Player. To Revert Versions Just Re-Use The Same Name.

--// DataStore Values
local defaultWins = 0 --// If There's No DataSave, It Will Set Their Wins To 0
local defaultPoints = 0 --// If There's No DataSave, It Will Set Their Points To 0

--// Functioning Part
game.Players.PlayerAdded:Connect(function(player)
    --// Sets Up Looks
    local leaderstats = Instance.new("Folder",player)
    leaderstats.Name = "leaderstats"

    local wins = Instance.new("IntValue",leaderstats)
    wins.Name = "Wins"

    local points = Instance.new("IntValue",leaderstats)
    points.Name = "Points"

    --// Sets Up Data
    local winsStore = DataStore2("Wins",player)

    local pointsStore = DataStore2("Points",player)

    --// Functions When Data Was Changed
    local function updateWins(newWins)
        player.leaderstats.Wins.Value = newWins
    end

    local function updatePoints(newPoints)
        player.leaderstats.Points.Value = newPoints
    end

    --// If No Data, Get's Default Value
    updateWins(winsStore:Get(defaultWins))

    updatePoints(pointsStore:Get(defaultPoints))

    --// Updates Data If Values Changed
    winsStore:OnUpdate(updateWins)

    pointsStore:OnUpdate(updatePoints)
end)

Here's More Information To Use: https://kampfkarren.github.io/Roblox/api/

If you have anymore questions, comment down below and I'll be glad to help! If this worked, let me know by taking this as the solution. If it didn't comment down below what went wrong and I'll try to fix it for you.

~killerbrenden

0
To Change the value you would use :Increment(howMuchToIncrement) or :Set(howMuchToSetTo) | Refer To The DS2 API For More Help, Or Even use Youtube. killerbrenden 1537 — 4y
Ad

Answer this question