Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
4

Why doesn't my data store actually save the data?

Asked by 5 months ago
Edited 5 months ago

Alright so pretty much only one weapon saves and I'm not sure why. I've tried having multiple data stores so it would work but nothing happens and it still shows up as 0. You don't have to read the whole thing just know that the ones that don't work are the M1911, AWP and more but I forgot but still what's the matter or is there a more efficient way since my game will have a lot of different weapons.

local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerWeaponStats")

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

    local key = "user-" .. player.userId

    local store = DataStore:GetAsync(key)

        --AK-12
        player.Class.WeaponStats["AK-12"].Kills.Value = store[1]
        player.Class.WeaponStats["AK-12"].Headshots.Value = store[2]
        player.Class.WeaponStats["AK-12"].BTs.Value = store[3]
        player.Class.WeaponStats["AK-12"].DKs.Value = store[4]
        player.Class.WeaponStats["AK-12"].LS.Value = store[5]

        --FAMAS
        player.Class.WeaponStats["FAMAS"].Kills.Value = store[6]
        player.Class.WeaponStats["FAMAS"].Headshots.Value = store[7]
        player.Class.WeaponStats["FAMAS"].BTs.Value = store[8]
        player.Class.WeaponStats["FAMAS"].DKs.Value = store[9]
        player.Class.WeaponStats["FAMAS"].LS.Value = store[10]

        --AS VAL
        player.Class.WeaponStats["AS VAL"].Kills.Value = store[11]
        player.Class.WeaponStats["AS VAL"].Headshots.Value = store[12]
        player.Class.WeaponStats["AS VAL"].BTs.Value = store[13]
        player.Class.WeaponStats["AS VAL"].DKs.Value = store[14]
        player.Class.WeaponStats["AS VAL"].LS.Value = store[15]

        --MK11
        player.Class.WeaponStats["MK11"].Kills.Value = store[16]
        player.Class.WeaponStats["MK11"].Headshots.Value = store[17]
        player.Class.WeaponStats["MK11"].BTs.Value = store[18]
        player.Class.WeaponStats["MK11"].DKs.Value = store[19]
        player.Class.WeaponStats["MK11"].LS.Value = store[20]

        --UMP45
        player.Class.WeaponStats["UMP45"].Kills.Value = store[21]
        player.Class.WeaponStats["UMP45"].Headshots.Value = store[22]
        player.Class.WeaponStats["UMP45"].BTs.Value = store[23]
        player.Class.WeaponStats["UMP45"].DKs.Value = store[24]
        player.Class.WeaponStats["UMP45"].LS.Value = store[25]

        --MP7
        player.Class.WeaponStats["MP7"].Kills.Value = store[26]
        player.Class.WeaponStats["MP7"].Headshots.Value = store[27]
        player.Class.WeaponStats["MP7"].BTs.Value = store[28]
        player.Class.WeaponStats["MP7"].DKs.Value = store[29]
        player.Class.WeaponStats["MP7"].LS.Value = store[30]

        --KSG 12
        player.Class.WeaponStats["KSG 12"].Kills.Value = store[31]
        player.Class.WeaponStats["KSG 12"].Headshots.Value = store[32]
        player.Class.WeaponStats["KSG 12"].BTs.Value = store[33]
        player.Class.WeaponStats["KSG 12"].DKs.Value = store[34]
        player.Class.WeaponStats["KSG 12"].LS.Value = store[35]

        local items = {

                player.Class.WeaponStats["AK-12"].Kills.Value;
                player.Class.WeaponStats["AK-12"].Headshots.Value;
                player.Class.WeaponStats["AK-12"].BTs.Value;
                player.Class.WeaponStats["AK-12"].DKs.Value;
                player.Class.WeaponStats["AK-12"].LS.Value;

                player.Class.WeaponStats["FAMAS"].Kills.Value;
                player.Class.WeaponStats["FAMAS"].Headshots.Value;
                player.Class.WeaponStats["FAMAS"].BTs.Value;
                player.Class.WeaponStats["FAMAS"].DKs.Value;
                player.Class.WeaponStats["FAMAS"].LS.Value;

                player.Class.WeaponStats["AS VAL"].Kills.Value;
                player.Class.WeaponStats["AS VAL"].Headshots.Value;
                player.Class.WeaponStats["AS VAL"].BTs.Value;
                player.Class.WeaponStats["AS VAL"].DKs.Value;
                player.Class.WeaponStats["AS VAL"].LS.Value;

                player.Class.WeaponStats["MK11"].Kills.Value;
                player.Class.WeaponStats["MK11"].Headshots.Value;
                player.Class.WeaponStats["MK11"].BTs.Value;
                player.Class.WeaponStats["MK11"].DKs.Value;
                player.Class.WeaponStats["MK11"].LS.Value;

                player.Class.WeaponStats["UMP45"].Kills.Value;
                player.Class.WeaponStats["UMP45"].Headshots.Value;
                player.Class.WeaponStats["UMP45"].BTs.Value;
                player.Class.WeaponStats["UMP45"].DKs.Value;
                player.Class.WeaponStats["UMP45"].LS.Value;

                player.Class.WeaponStats["KSG 12"].Kills.Value;
                player.Class.WeaponStats["KSG 12"].Headshots.Value;
                player.Class.WeaponStats["KSG 12"].BTs.Value;
                player.Class.WeaponStats["KSG 12"].DKs.Value;
                player.Class.WeaponStats["KSG 12"].LS.Value;
                }


        DataStore:SetAsync(key, items)
end)

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

    local items = {

                player.Class.WeaponStats["AK-12"].Kills.Value;
                player.Class.WeaponStats["AK-12"].Headshots.Value;
                player.Class.WeaponStats["AK-12"].BTs.Value;
                player.Class.WeaponStats["AK-12"].DKs.Value;
                player.Class.WeaponStats["AK-12"].LS.Value;

                player.Class.WeaponStats["FAMAS"].Kills.Value;
                player.Class.WeaponStats["FAMAS"].Headshots.Value;
                player.Class.WeaponStats["FAMAS"].BTs.Value;
                player.Class.WeaponStats["FAMAS"].DKs.Value;
                player.Class.WeaponStats["FAMAS"].LS.Value;

                player.Class.WeaponStats["AS VAL"].Kills.Value;
                player.Class.WeaponStats["AS VAL"].Headshots.Value;
                player.Class.WeaponStats["AS VAL"].BTs.Value;
                player.Class.WeaponStats["AS VAL"].DKs.Value;
                player.Class.WeaponStats["AS VAL"].LS.Value;

                player.Class.WeaponStats["MK11"].Kills.Value;
                player.Class.WeaponStats["MK11"].Headshots.Value;
                player.Class.WeaponStats["MK11"].BTs.Value;
                player.Class.WeaponStats["MK11"].DKs.Value;
                player.Class.WeaponStats["MK11"].LS.Value;

                player.Class.WeaponStats["UMP45"].Kills.Value;
                player.Class.WeaponStats["UMP45"].Headshots.Value;
                player.Class.WeaponStats["UMP45"].BTs.Value;
                player.Class.WeaponStats["UMP45"].DKs.Value;
                player.Class.WeaponStats["UMP45"].LS.Value;

                player.Class.WeaponStats["KSG 12"].Kills.Value;
                player.Class.WeaponStats["KSG 12"].Headshots.Value;
                player.Class.WeaponStats["KSG 12"].BTs.Value;
                player.Class.WeaponStats["KSG 12"].DKs.Value;
                player.Class.WeaponStats["KSG 12"].LS.Value;
                }

    local key = "user-" .. player.userId

    DataStore:SetAsync(key, items)

end)

Their is more it's just I had to remove some.

0
It might be useful to learn how to implement a generic for loop in your situation. User#25115 0 — 5mo
0
I don't get it GameBoyOtaku 33 — 5mo
0
You had the patience to write all of this? incapaxx 3172 — 5mo
0
Yes I did GameBoyOtaku 33 — 5mo
View all comments (4 more)
0
use for loops yHasteeD 1573 — 5mo
0
can I see an example please GameBoyOtaku 33 — 5mo
0
thank you GameBoyOtaku 33 — 5mo
0
Whys this have so many upvotes DinozCreates 746 — 5mo

Answer this question