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

My save data script doesn't work. I tried everything. How to fix it? (ROBLOX STUDIO)

Asked by
zkkf56 -5
5 years ago
Edited 5 years ago

Hi, In first sorry for my english, but I'm from Poland

I don't know what doesn't work. I made Data Saving script:

local DataStores = game:GetService("DataStoreService"):GetDataStore("MoneyDataStore")
local playersLeft = 0
local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')

game.Players.PlayerAdded:Connect(function(player)

       playersLeft = playersLeft + 1

 local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
 leaderstats.Parent = player

 local money = Instance.new("IntValue")
 money.Name = "StageSkips"
 money.Parent = leaderstats
local uniquekey = 'id-'..player.userId
local savevalue = Instance.new('IntValue')
savevalue.Parent = leaderstats
savevalue.Name = 'Stage'

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

      -- Data Stores

    local player_data

    pcall(function()
     player_data = DataStores:GetAsync(player.Userid.."-money") --1736284-Money
    end)

    if player_data ~= nil then
     -- Player has saved data , load it in
     money.Value = player_data
    else
     -- New player 
    print("It isn't player data oof")
     money.Value = 0
    end

end)

game.Players.PlayerRemoving:Connect(function(player)
    local uniquekey = 'id-'..player.userId 
    local Savetable = {player.leaderstats.Stage.Value}
    DSService:SetAsync(uniquekey,Savetable)
     DataStores:SetAsync(player.UserId.."-money",player.leaderstats.StageSkips.Value)

end)

And "Stage" work, it's saving, loading etc., but StageSkips doesn't work, when i run the script Stage work, but StageSkips doesn't work, and in output appears "It isn't player data oof"

Thanks in advance

0
PS the first code as a second also does not work zkkf56 -5 — 5y
0
try it outside of studio DeceptiveCaster 3761 — 5y
0
it's don't work anyway zkkf56 -5 — 5y

1 answer

Log in to vote
0
Answered by
zkkf56 -5
5 years ago

Ok, i used other code and it's work

Ad

Answer this question