Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[solved] DataStore for tools isn't working with no errors but printing things correctly, any help?

I wanted to make a DataStore for tools. There are no errors whatsoever. Every number I print is printed in the output but the tools I was expecting isn't coming up.

local dss = game:GetService('DataStoreService')
local backpackds = dss:GetDataStore('BackpackStore')
local equipped = nil
game.Players.PlayerAdded:Connect(function(plr)
	local backpack = plr.Backpack
	local data = backpackds:GetAsync(plr.UserId)
	if data then
		for i, _ in pairs(backpack:GetChildren()) do
			_:Destroy()
		end
		print(0) 
		for i,_ in pairs(data) do
			print(12)
			if game.ReplicatedStorage:WaitForChild('Tools'):FindFirstChild(_) then
				print(1)
				local tool = game.ReplicatedStorage.Tools[_]
				local clonedver = tool:Clone()
				clonedver = backpack
				print(2)
			end
		end
	end	
	plr.CharacterAdded:Connect(function(c)
		c.ChildAdded:Connect(function(_)
			if _:IsA('Tool') then
				equipped = _
			end
			
		end)
		
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	
	local backpack = plr.Backpack
	local data = {}
	for i, v in pairs(backpack:GetChildren()) do
		table.insert(data,v.Name)
	end	
	if equipped then
		
		table.insert(data,equipped.Name)

	end
	local success, msg = pcall(function()
		backpackds:SetAsync(plr.UserId,data)
	end)

	if not success then
		print('Error:',msg)
	else
		print('Saved Backpack for player',plr.Name)
	end
end)

I check the table in the DataStore plugin and it should've worked.

I deleted all tools since it was the starter tools.

I probably did something wrong getting the data but I don't know what...

Any suggestion/help is appreciated!

1 answer

dude, I DID CLONEDVAR = BACKPACK AND NOT CHANGE THE PARENT ;-;

This discussion is preserved as it was. New answers, comments, and votes are closed.