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

Data storing items?

Hi, I was playing a game and I bought some particles then left then re-joined the game and I still had my particles. I know this is datastore because I've used datastore, but I only know how to store number/string values. I was trying to save items but my script didn't work. Can you please tell me what I did wrong?

game.Players.PlayerAdded:connect(function(player)
	local stats = Instance.new("IntValue",player)
	stats.Name = "leaderstats"
	local credits = Instance.new("IntValue",stats)
	credits.Name = "Credits"
	
	local key = "Player-"..player.UserId
	local PDS = DataStore:GetAsync(key)
		if PDS ~= nil then
			credits.Value = PDS 
		else
			DataStore:SetAsync(key, credits.Value)
		end
	credits.Changed:connect(function()
	    local key = 'Player-'..player.UserId
	    DataStore:SetAsync(key,credits.Value)
	    end)
	repeat wait() until player:WaitForChild("DataFolderStore")
	player.DataFolderStore.Changed:connect(function() -- This is where it doesn't work
		local key = 'Player-'..player.UserId
		DataStore:SetAsync(key,player.DataFolderStore:GetChildren())
	end)
end)

Script to insert the folder:

game.Players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "DataFolderStore"
end)

Please help!

3 comments

0

I don't think you can save anything other then values or lua tables from Data Store.

0

You can't save instances but you can try saving a string which would be the name of the particle and have the particle somewhere in ServerStorage and then make a script to clone the right particle into the player's character.

1 answer

✓ Accepted answer

Describe what they have
So, I have this box...

The fundamental thing about DataStores is that it can only store primitive data which can be serialized into a JSON-Compatible format. What this means for you is that you can't save their sparkles, but you can save that they have sparkles and what kind of sparkles they have.


For a practical example, consider an RPG game. You can't save the weapon they have, but you can save the type of weapon and the information about it. This is called serialization, and it's actually done behind the scenes with a lot of the network functions on Roblox.

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