Need suggestions on setting a base idea on how I will do this

  1. What do you want to achieve? Keep it simple and clear!
    Successfully get the tools a player has when he/she leaves then joins, DataStore.
  2. What is the issue? Include screenshots / videos if possible!


local DSS = game:GetService("DataStoreService")
local myToolDSS = DSS:GetDataStore("myToolDSS")

game.Players.PlayerAdded:Connect(function(player)
	local data
	local success, errormessage = pcall(function()
		data = myToolDSS:GetAsync(player.UserId.."-tools")
	end)
	if success then
		print(data)
	else
		print("There was an error whilst getting your data.")
		warn(errormessage)
	end
end)
game.Players.PlayerRemoving:Connect(function(player)

	local success, errormessage = pcall(function()
		local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
		getToolsEvent.OnServerEvent:Connect(function(player, myTools)
			local ownedTools = myTools.Value
			print(ownedTools)
			myToolDSS:SetAsync(player.UserId.."-tools", ownedTools.Value)

		end)
		
	end)
	if success then
		print("Data successfully saved!")
		
	else
		print("There was an error saving your data.")
		warn(errormessage)
	end
	
	
	
end)

What the output looks like after printing


I made it as a table so that multiple tools can be saved. Can anyone set a base idea for me? My goal is to just get the tools (values which represent the names) when a player joins. I am not requesting for a whole script, just an idea and probably some minor scripting mistakes I had missed.

You could use HttpService and the JSONEncode function to convert the table to a string. The string could then be saved to a DataStore. Then when the player rejoins/joins, the server can get the same string from the data store (if ther player has played before) and then use the JSONDecode function to convert it back into a table. You could then write code to read the list and add the corresponding items to the player’s inventory.

Unfortunately, you cannot save it as a table to the data store as it is no supported by roblox.

Here is the documentation for HttpService if you are unsure:
HttpService - Documentation

1 Like

Wow, this is the exact solution I was looking for! Bless you and your knowledge. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.