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

Help With Saving Levels and Experience?

Asked by 7 years ago
Edited 7 years ago

So basically I have made a script to save cash for the game, however I am trying to make different scripts of the same thing to save them. It is not working on anything I do and I need help on how to save all three things in just one script so I can use them under a Data category instead of leaderstats so there is no leaderboard. Thanks!

I would like to use something under my knowledge to

Here are the scripts.

SAVE CASH

local DSService = game:GetService('DataStoreService'):GetDataStore('Cash')
game.Players.PlayerAdded:connect(function(plr)
    -- Define variables
    local uniquekey = 'id-'..plr.userId
    local leaderstats = Instance.new('IntValue', plr)
    local savevalue =  Instance.new('IntValue')
    leaderstats.Name = 'leaderstats3'
    savevalue.Parent = leaderstats
    savevalue.Name = 'Cash'

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        savevalue.Value = GetSaved[1]
    else
        local NumbersForSaving = {savevalue.Value}
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats3.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)    


end)

*HAVE LEVEL AND XP *

game.Players.PlayerAdded:connect(function(Player) ----- When a Player joins a server this function happens
    local Data = Instance.new("IntValue",Player) ----Makes an IntValue inside Player
    Data.Name = "Data" -----It's name is Data ([Note]: You could change it to leaderstats if you would like a leaderboard with it.)
    local XP = Instance.new("IntValue",Data) ----Makes a IntValue inside Data
    XP.Name = "XP" 
    XP.Value = 0
    local Level = Instance.new("IntValue",Data) ------- Makes an IntValue Inside Data
    Level.Name = "Level" ------- It's name is Level
    Level.Value = 1 
    local Tries = Instance.new("IntValue",Data)
    Tries.Value = 10
    Tries.Name = "Tries"

    XP.Changed:connect(function() XPChange(Player,XP,Level) end) ---- To change the XP, XPChanged function occours

end)

function XPChange(Player,XP,Level) ------ XPChanged function
    if XP.Value >= Level.Value*150  then ----- this function occours happens if the Level's Value is greater or equal to this 150 ([Note]: Change 150 to the max XP)
        XP.Value = 0 --- Resets the XP
        Level.Value = Level.Value+ 1
    end
end

Thanks! Also remember I need help scripting something like the first script, but saving all three things.

0
Oh, your an AlvinBlox fan. Most of his vids are outdated SH_Helper 61 — 7y
0
Don't really understand what your question is? Do you want to combine them all or something else? User#13152 0 — 7y
0
I want to combine them all into one script that saves them. Theevilem 23 — 7y
0
Observe what each part of the script does, since Lua is kinda self-explainatory when u see it. SH_Helper 61 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Heres a tutorial!

Ad

Answer this question