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

why is my game not auto saving the wins?

Asked by 7 years ago

hi scripter, so, ive just made a auto save and leaderboard (on top of screen) But the save does not save... If you want to see it, here you go! https://www.roblox.com/games/722511272/Jumpy-racing-Under-construction But what am I doing wrong?

leaderboard

game.Players.PlayerAdded:connect(function(plr)
    local stats = Instance.new('IntValue', plr)
    stats.Name = 'leaderstats'
    local Points = Instance.new ('IntValue', stats)
    Points.Name = 'Wins'
end)

OrderedDataStore AutoSave

local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')
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 = 'leaderstats'
    savevalue.Parent = leaderstats
    savevalue.Name = 'Wins'

    -- 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.leaderstats.Wins.Value}
DSService:SetAsync(uniquekey, Savetable)    


end)

I hope you can help me out! thanks! good luck with other scripting!

-Gamer_io

0
This is not an ordered data store this is a global data store. User#5423 17 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Paste this in a normal script inside of "ServerScriptService"

GetService = game:GetService("DataStoreService")
local Storage = GetService:GetDataStore("Hamburger223232")

game.Players.PlayerAdded:connect(function(Player)
    --LEADERSTATS--
    local User = Player.userId
    local UserKey = "User_"..User
    local SavedData = Storage:GetAsync(UserKey)
    local Stats = Instance.new("IntValue", Player)
    Stats.Name = "leaderstats"

    local Wins = Instance.new("IntValue", Stats)
    Wins.Name = "Wins"
    Wins.Value = 0

    --DataStore--
    if SavedData then
        Wins.Value = SavedData[1]
    else
        local NumbersNeeded = {Wins.Value}
        Storage:SetAsync(UserKey, NumbersNeeded)
    end
end)

game.Players.PlayerRemoving:connect(function(Player)
    local User = Player.userId
    local UserKey = "User_"..User
    local Savetable = {Player["leaderstats"].Wins.Value}
    Storage:SetAsync(UserKey, Savetable)
end)

Already Tested it and it works great!

0
Be sure to check off the "Answered" box so I can get some points. SilentGalaxZy 53 — 7y
0
Thanks, it realy helped me! Gamer_io 14 — 7y
Ad

Answer this question