Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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!

5 comments

0

btw I'm supposed to be doing Geography rn lol

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)...

1

Any chance you could show me an example of the DataStore list?

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"} } }

0

and "WOODEN_SWORD" and "DIAMOND_SWORD" would be Item IDs, stored in a ModuleScript.

This discussion is preserved as it was. New answers, comments, and votes are closed.