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

Any suggestions on how to save FPS Classes in a data store?

Asked by 5 years ago

I've asked something similar to this but I couldn't understand it that much so I just need a brief answer, I don't need a script.

Basically, I'm making a FPS and the main problem I have is the data store. Of course I want to save your hard work within the game and all the stats in it but I'm not much of a data store genius or one at all and I keep failing, the script I'm currently using was pretty much off of a YouTube comment and it kinda works for saving multiple values but it's just repetitive and only saves some data.

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

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

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


    local store = DataStore:GetAsync(key)

        player.Class.Stats.Kills.Value = store[1]
        player.Class.Stats.Deaths.Value = store[2]
        player.Class.Stats.Headshots.Value = store[3]
        player.Class.Killstreaks.Nukes.Value = store[4]
        player.Class.Stats.XP.Value = store[5]
        player.Class.Stats.Level.Value = store[6]
        player.Class.Stats.Prestige.Value = store[7]




        local items = {
                player.Class.Stats.Kills.Value;
                player.Class.Stats.Deaths.Value;
                player.Class.Stats.Headshots.Value;
                player.Class.Killstreaks.Nukes.Value;
                player.Class.Stats.XP.Value;
                player.Class.Stats.Level.Value;
                player.Class.Stats.Prestige.Value;
                }


        DataStore:SetAsync(key, items)

        print("Player Data Collected")

    player.Class.Stats.XP.Changed:connect(function() xp(player, player.Class.Stats.XP, player.Class.Stats.Level) end)


end)

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

    local items = {
                player.Class.Stats.Kills.Value;
                player.Class.Stats.Deaths.Value;
                player.Class.Stats.Headshots.Value;
                player.Class.Killstreaks.Nukes.Value;
                player.Class.Stats.XP.Value;
                player.Class.Stats.Level.Value;
                player.Class.Stats.Prestige.Value;
                }

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

    DataStore:SetAsync(key, items)

    print("Player Data Saved!")
end)

function xp(player, xp, level)
    if xp.Value >= level.Value * 500 then
        if level.Value <=54 then
        xp.Value = 0
        level.Value = level.Value + 1
        print("Level Up")
        end
    end
end

game.ReplicatedStorage.EmoteSelected.OnServerEvent:Connect(function(player, emote, placement)
    player.Class.Emotes[placement].Value = emote
    print(emote)
end)


game.ReplicatedStorage.CamoSelected.OnServerEvent:Connect(function(plr, active, camo, kind)

    print(camo)

    if kind == "Primary" then

        plr.Class[active].PrimaryCamo.Value = camo

    elseif kind == "Secondary" then

     plr.Class[active].SecondaryCamo.Value = camo

    end
end)

That's the short version, I use 2 scripts for the saving.

What I'm Trying To Save

What's in the classes to save

I know the script I have is bad but I just need some suggestions because I've been stuck with this for about a month now and it's the only reason I'm not pushing my game out.

Any help will be appreciated!

0
isn't this opinion based? I tihnk it is DeceptiveCaster 3761 — 5y
0
think DeceptiveCaster 3761 — 5y
0
since you're saving right after getting the data , you should use getasync kisty1 111 — 5y
0
you could try DataStore2 farizarps 132 — 5y
View all comments (2 more)
0
I don't think that it is primarily opinion-based as he just asked for any ideas. A primarily opinion-based question is e.g 'How to make a function what always returns 5'. There are more solutions to this question, but same with every other questions (this is my opinion) Miniller 562 — 5y
0
Are you trying to save all the values in these folders? or just the ones listed in the gyzao image and this script? Also what kinds of values are you using? i.e. BoolValue, IntValue, etc. SerpentineKing 3885 — 5y

Answer this question