Database problem

Hello again guys. I made a script to save items using the database system according to the guide on YouTube, but something goes wrong and the UnquipTools value is not found or simply does not exist. Help me to understand!

UnquipTools is not a valid member of Humanoid "Workspace.MaaXGaz20.Humanoid"
local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("playersitem")
local Repstore = game:GetService("ReplicatedStorage")
local toolsFolder = Repstore:WaitForChild("Tools")

game.Players.PlayerAdded:Connect(function(plr)

	local savedItems = data:GetAsync(plr.UserId.."-Items")

	if savedItems then
		for i, item in pairs(savedItems) do
			for i, tool in pairs(toolsFolder:GetChildren()) do
				if item == tool.Name then

					local toolClone1 = tool:Clone()
					toolClone1.Parent = plr.Backpack

					local toolClone2 = tool:Clone()
					toolClone2.Parent = plr.StarterGear



				end
			end
		end
	end


end)

game.Players.PlayerRemoving:Connect(function(plr)

	plr.CharacterRemoving:Connect(function(char)
		local humanoid = char.Humanoid

		humanoid:UnquipTools()
	end)

	local suc, err = pcall(function()

		local savedItems = {}

		for i, item in pairs(plr.Backpack:GetChildren()) do
			table.insert(savedItems, item.Name)
		end

		data:SetAsync(plr.UserId.."-Items", savedItems)

	end)

end)

2 Likes

It is spelled UnequipTools, you are missing an “e”.

bruh, Yes, this fixed the error, but saving and receiving items does not work(

Why are you uneqipping the items inside the PlayerRemoving function?

Bro I don’t know. I did this from a video tutorial on YouTube. I’ve never worked with a database.

looks like it’s building a database of backpack items … thus the unequip.

What can I do with this? help me please

Seems to be doing some odd things here … all you need to do is call the UnequipTools()
Then build the database … Locate the humanoid, call UnequipTools(), create datastore.
Looks like you’re on the right path here. Just not sure if you have all the time needed to pull this off.
Might be something you may have to do when they get a new item …

Without creating a database to check this … here is a simple rewrite to catch some obvious errors.

local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("playersitem")
local Repstore = game:GetService("ReplicatedStorage")
local toolsFolder = Repstore:WaitForChild("Tools")

game.Players.PlayerAdded:Connect(function(plr)

	local savedItems = data:GetAsync(plr.UserId..Value.."-Items")

	if savedItems then
		for _, item in pairs(savedItems) do
			for _, tool in pairs(toolsFolder:GetChildren()) do
				if item == tool.Name then
					local toolClone = tool:Clone()
					toolClone.Parent = plr.Backpack

					local toolClone2 = tool:Clone()
					toolClone2.Parent = plr.StarterGear
				end
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	plr.CharacterRemoving:Connect(function(char)
		local humanoid = char:FindFirstChild("Humanoid")
		if humanoid then
			humanoid:UnequipTools()
		end
	end)

	local savedItems = {}
	for _, item in pairs(plr.Backpack:GetChildren()) do
		if item:IsA("Tool") then
			table.insert(savedItems, item.Name)
		end
	end

	data:SetAsync(plr.UserId.."-Items", savedItems)
end)

I hĐ°ve nil string Đ°t 8 stroke.VĐ°lue hĐ°ve unknown globĐ°l. blue line
ServerScriptService.DataBaseItems:8: attempt to concatenate nil with string

Try this
local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("playersitem")
local Repstore = game:GetService("ReplicatedStorage")
local toolsFolder = Repstore:WaitForChild("Tools")

game.Players.PlayerAdded:Connect(function(plr)
    local savedItems = data:GetAsync(plr.UserId .. "-Items")

    if savedItems then
        for _, item in pairs(savedItems) do
            for _, tool in pairs(toolsFolder:GetChildren()) do
                if item == tool.Name then
                    local toolClone = tool:Clone()
                    toolClone.Parent = plr.Backpack

                    local toolClone2 = tool:Clone()
                    toolClone2.Parent = plr.StarterGear
                end
            end
        end
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    plr.CharacterRemoving:Connect(function(char)
        local humanoid = char:FindFirstChild("Humanoid")
        if humanoid then
            humanoid:UnequipTools()
        end
    end)

    local savedItems = {}
    for _, item in pairs(plr.Backpack:GetChildren()) do
        if item:IsA("Tool") then
            table.insert(savedItems, item.Name)
        end
    end

    data:SetAsync(plr.UserId .. "-Items", savedItems)
end)