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

What's the best way to save what items a player has?

Asked by 4 years ago

I'm trying to figure out the best way to save the swords a player owns. My current way is just a number for each sword but I realized this won't work for more swords. I was thinking of making a data save for every sword and making it 1 for owning and 0 for not but I thought there might be a better way.

Heres what I currently have:

game.ReplicatedStorage.Purchase.OnServerEvent:Connect(function(Player, Sword)
    if Sword == "Bronze Sword" and Player.leaderstats.Points.Value >= 25 and Player.EquipedSword.Value ~= 2 and Player.EquipedSword.Value ~= 23 then
        Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - 25
        Player.PlayerGui.SwordShop.Frame.Bronze.Text = "[OWNED] Bronze Sword"
        if Player.EquipedSword.Value == 3 then
            Player.EquipedSword.Value = 23
        else 
            Player.EquipedSword.Value = 2
        end
    elseif Sword == "Iron Sword" and Player.leaderstats.Points.Value >= 50 and Player.EquipedSword.Value ~= 3 and Player.EquipedSword.Value ~= 23  then
        Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - 50
        Player.PlayerGui.SwordShop.Frame.Iron.Text = "[OWNED] Iron Sword"
        if Player.EquipedSword.Value == 2 then
            Player.EquipedSword.Value = 23
        else 
            Player.EquipedSword.Value = 3
        end
    end
end)

Thanks in advance.

1 answer

Log in to vote
0
Answered by 4 years ago

I'd say give each Item an ID code (or just use it's name), and save the list of IDs to a DataStore, so every time they join, it goes through maybe a table or ModuleScript of IDs, and if they have that ID, it gives them the correlating Item. I'm at school so i don't have time to code it though, sorry!

0
btw I'm supposed to be doing Geography rn lol sweettart13947 105 — 4y
0
I just save a table of all the items a player owns(all the names). All the weapon information is static data that is in a module and not saved.(yes I know that is what sweet said)... ForeverBrown 356 — 4y
1
Any chance you could show me an example of the DataStore list? xXGokyXx 46 — 4y
0
Note: Datastores aren't tables, I'm just using it to represent a datastore.. DataStore: { id_123 = { OwnedItems = {"WOODEN_SWORD", "DIAMOND_SWORD"} }, id_456 = { OwnedItems = {"WOODEN_SWORD"} } } sweettart13947 105 — 4y
0
and "WOODEN_SWORD" and "DIAMOND_SWORD" would be Item IDs, stored in a ModuleScript. sweettart13947 105 — 4y
Ad

Answer this question