I'm making a datastore where players' shop items get saved. I want to make it so that if a player has no items saved, a tutorial GUI pops up and gives them a tutorial. Here's my code:

local ds = game:GetService("DataStoreService"):GetDataStore("ToolSave")
game.Players.PlayerAdded:connect(function(plr)
	local key = "id-"..plr.userId
	pcall(function()
		local animation = ds:GetAsync(key)
		if animation then
			for i,v in pairs(animation) do
				local took = game.ServerStorage.Tools:FindFirstChild(v)
				if animation then
					animation:Clone().Parent = plr:WaitForChild("Backpack")
					animation:Clone().Parent = plr:WaitForChild("StarterGear")
				end
			end
		end
	end)
end)
game.Players.PlayerRemoving:connect(function(plr)
	local key = "id-"..plr.userId
	pcall(function()
		local toolsToSave = {}
		for i,v in pairs(plr.Backpack:GetChildren()) do
			if v then
				table.insert(toolsToSave,v.Name)
			end
		end
		ds:SetAsync(key, toolsToSave)
	end)
end)

I'm thinking that I should put an if statement and if there are no items in the backpack/startergear, the tutorial should automatically begin. Is there a better, more efficient way to start a tutorial? Thank you.

1 comment

0

if the player doesn't have any saved data then it's their first time playing. (pretty much what you're doing, just including an extra step). though keep in mind it'll only play once, instead of every time they have no items