How can I save my Backpack?

How am I able to save players backpack, So basically i have made an Element spin system in my game so it takes the folder where the element is and it puts it into your backpack so you can use the skills, it’s not a tool. The only problem is that every time that the player leaves it doesn’t save the folder in the player’s backpack.

3 Likes

You will need to implement a saving system using Datastore. This is a relatively easy thing to do. Refer to the resources attached:

AlvinBlox - Datastore Tutorial
Roblox Wiki - DataStoreService

Best of luck!

1 Like

Thank you , but I have already watch those videos but that only save my leaderstats

2 Likes

Thank you, but what I’m trying to save is not a tool. I’m very grateful you tried though have a great night/day!

you simply have to save a string as: “Fire” or “Lightling”, then create a variable with the folder that contains all the elements inside and use the FindFirstChild function to find the element that the player has

Can you show me an example sorry , im new.

Maybe this can help you?

Thank you, but what I’m trying to save its not a tool.

But I think it could make use for your element saving. Why I say it could, well it’s because he save the tools inside a table then saving it meaning that you could put the elements into a table then save it.

hope this can help you:


local data_store = game:GetService("DataStoreService")

local elements_store = data_store:GetDataStore("elements")

local players = game:GetService("Players")

local elements_foler = "" -- you should have a folder with all the items inside

players.PlayerAdded:Connect(function(player)
	
	local element
	
	local backpack = player.Backpack
	
	local key = "Player_"..player.UserId
	
	local success , element = pcall(function()
	
		return elements_store:GetAsync(key)
		
	end)
	
	if success then
		
		element = elements_foler:FindFirstChild(element):Clone()
		
		element.Parent = backpack
		
	else
		
		elements_store:SetAsync(key,backpack:GetChildren()[1]) -- the player may not have chosen the item yet, so it may give an error
		
	end
	
end)

I forgot to put .Name in it, use this:


local data_store = game:GetService("DataStoreService")

local elements_store = data_store:GetDataStore("elements")

local players = game:GetService("Players")

local elements_foler = "" -- you should have a folder with all the items inside

players.PlayerAdded:Connect(function(player)
	
	local element
	
	local backpack = player.Backpack
	
	local key = "Player_"..player.UserId
	
	local success , element = pcall(function()
	
		return elements_store:GetAsync(key)
		
	end)
	
	if success then
		
		element = elements_foler:FindFirstChild(element):Clone()
		
		element.Parent = backpack
		
	else
		
		elements_store:SetAsync(key,backpack:GetChildren()[1].Name) -- the player may not have chosen the item yet, so it may give an error
		
	end
	
end)

Its saying that your trying to call a nil value in line 25, How can I fix it?

can i see what you put in the script?

May I ask is the elements in the player backpack?

1 Like

My elements are Fire and Lightning

do you have a folder with all the elements inside?

Yes I do have a folder that is named Elements and it does have both of my elements in there.

can you send a picture of this folder?