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

Data Storage won't save?

Asked by 5 years ago

I don't really know how to script data storage, so I watched a video about it and came up with this. The script is almost identical to the one in the video excepting the stringvalues. Everyone commenting the video claim it works but for me it doesn't save. I have API enabled in the game I'm scripting it. Is it because of the stringvalues?

local Data = game:GetService("DataStoreService"):GetDataStore("Loadout_Saving")

game.Players.PlayerAdded:Connect(function(plr)
    local Folder = Instance.new("Folder",game.ServerStorage:FindFirstChild("CurrentLoadout"))
    Folder.Name = plr.Name
    local Primary = Instance.new("StringValue",Folder)
    Primary.Name = "Primary"
    local Secondary = Instance.new("StringValue",Folder)
    Secondary.Name = "Secondary"
    local SavedItems = Data:GetAsync(plr.userId)
    if SavedItems then
        Primary.Value = SavedItems.Primary or "None"
        print(Primary.Value)
        Secondary.Value = SavedItems.Secondary or "None"
        print(Secondary.Value)
    else
        Primary.Value = "None"
        Secondary.Value = "None"
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)

    local Saving = {["Primary"] = game.ServerStorage.CurrentLoadout:FindFirstChild(plr.Name).Primary.Value;
                    ["Secondary"] = game.ServerStorage.CurrentLoadout:FindFirstChild(plr.Name).Secondary.Value
    }
    Data:SetAsync(plr.userID,Saving)

end)
0
Did you test it in an online server? Data doesn't save in studio hellmatic 1523 — 5y
0
The 2nd arguement of Instance.new is deprecated. green271 635 — 5y
0
^it isnt really deprecated just advised against due to performance issues radusavin366 617 — 5y
0
since when was instance.new deprecated? stinkyest11 78 — 5y
View all comments (6 more)
0
he meant setting the parent through the 2nd parameter (Instance.new(instance name, *parent*)) radusavin366 617 — 5y
0
Yes, I tested it in an online server and it didn't work. Checked while online with a print command whilde in developer console. Lamantinel -1 — 5y
0
for some reason player removing doesn't work for me. Try putting the set async in a loop greatneil80 2647 — 5y
0
Data do save in studio. LinKiNSpitZ 22 — 5y
0
I didn't try in studio, I'll try the set async in a loop when I can and update. Lamantinel -1 — 5y
0
@radusavin it IS deprecated. Look it up yourself. User#19524 175 — 5y

Answer this question