How do i make a datastore that saves knives?

try to change your knife value into table with name, equipped boolean, damage ect, and when player joins check data and look for knife value if value then …

i was talking about the solution @Herobrinekd1 told me, i printed the value when i bought a couple of knives and it gave me:

 {
                    [1] = "Pencil Knife",
                    [2] = "Fire Knife",
                    [3] = "Melon Knife"
                 }

now that’s what i am trying to save to a datastore and as i said i suck with datastores its my “biggest enemy”

Its pretty simple axtually. All you’ve got to do is type the following:

Though also be aware that each “SetAsync()” call on a key has a 6 seconds cooldown. If you attempt to perform another set request under that time period the request will be put onto a queue.

local Service = game:GetService("DataStoreService")



local MyStorage = Service:GetDataStore("Test Storage") -- // Your DataStore name.



local MyDictionary = {
	["Herobrinekid1"] = {
		"Pencil Knife",
		"Fire Knife",
		"Melon Knife",
	}
}



local UserId = 36533345 -- // Using myself for demonstration X)




local Sucess: boolean, Res: boolean = pcall(MyStorage.SetAsync,MyStorage,UserId,MyDictionary)

--[[
Same as doing:

local Sucess, Res = pcall(function()
MyStorage:SetAsync(UserId,MyArray)
end)


--]]

-- // I just prefer using a pcall that way X)


-------------------------------------------

-- // For debugging purposes. 
if Sucess then
	warn("Yay!! my array was saved :D")
else
	warn("My array wasnt saved D:")
	warn(Res)
end
1 Like

gives me: Argument 2 missing or nil

local Service = game:GetService("DataStoreService")



local Datastore = Service:GetDataStore("Knives") -- // Your DataStore name.

game.Players.PlayerAdded:Connect(function(plr)
	local Storage = require(game.ServerScriptService.ModuleKnives)
	local saveditems = Datastore:GetAsync(plr.userId)

	if saveditems then
		local PlayerStorage = Storage[plr.UserId]
		PlayerStorage = saveditems
	else
		
	end
end)


game.Players.PlayerRemoving:Connect(function(plr)
	local Storage = require(game.ServerScriptService.ModuleKnives)
	local PlayerStorage = Storage[plr.UserId]
	
	local Sucess, Res = pcall(function()
		Datastore:SetAsync(plr.UserId,PlayerStorage)
	end)
	
	if Sucess then
		warn("Yay!! my array was saved :D")
	else
		warn("My array wasnt saved D:")
		warn(Res)
	end
end)

Use folders and tables also some stringvalues to save player knives in the said folder.

what do you mean? can you be a bit more specific?

Loop through the stringvalues (of which contain the skin data like name) then save them.
0 = Not owned
1 = Owned

just how do i fix this bug? i already have someone who helped me but i need help fixing that bug

What piece of code gives you the error?

There’s a module I know that is able to convert an instance to a table or convert that table to an instance while keeping all the same properties the instance had before. Here it is: Converter Module: Instance ↔ Table | Save Instances to DataStores and More!

I use it for my building game where players have plots and they could build stuff from blocks on them with different block shapes, colours and materials. This module has saved me so much time and brainstorms, I am very thankful for it even being a thing.

The best thing is that it works lightning fast and doesn’t even lag.

Here are the features:

  • Supports the DataStore/DataStore2 format.
  • Supports object variables.
  • Supports Workspace and Lighting properties.
  • Can be used without HTTP Service.
  • Many customizable settings available.
  • Complete backwards compatibility.
  • Full attribute support.
  • Supports ALL data types (CFrame, String, Vector3, UDim2, Ray, Faces, etc.)
  • Compatible with the ModuleScripts created from the Instance to ModuleScript Converter plugin.

it’s not an instance, it’s a module that includes the names of the wep

no line, its doing the

warn(Res)

part

Well, earlier you talked about knives, what’s up?

actually, do you know how i would make a system that stores how many knives you have? i suck at datastores so i need really good explanation. also you are supposed to be able to have more than 1 knife.

You can just use IntValues/NumberValues.

though won’t that make me have to create unnecessarily many intvalues?

Depends on how many knives you got. You can just store the intvalues in a folder.

i’m probably gonna add a lot of knives

Well I can’t think of any other solution and this is probably the most effective.

ah, well that sucks i guess that’s one of my only resorts :confused:

1 Like