local DataStore = game:GetService("DataStoreService"):GetDataStore("tools")
game.Players.PlayerAdded:connect(function(plr)
	wait(1)
	local items = DataStore:GetAsync(plr.UserId) or {}
	if game.Workspace:FindFirstChild(plr.Name.."'s Holder") == nil then
		local folder = Instance.new("Folder", game.Workspace)
		folder.Name = plr.Name.."'s Holder"
		local folder = Instance.new("Folder", folder)
		local playername = Instance.new("StringValue",folder)
		playername.Name = "PlayerName"
		playername.Value = plr.Name
		wait(0.5)
		for i, v in pairs(items) do
			if game.ReplicatedStorage.tools:FindFirstChild(v) ~= nil then
				game.ReplicatedStorage.tools:FindFirstChild(v):Clone().Parent = folder
			end		
		end
		folder.ChildAdded:Connect(function(C)
			items[#items+1] = C.Name
			DataStore:SetAsync(plr.UserId, items)
			print("Saving to table")
		end)
		folder.ChildRemoved:Connect(function(c)
			items = {}
			items[#items-1] = c.Name
			DataStore:SetAsync(plr.UserId, items)
			print("Something removed from table...Saving table.")
		end)
	else
		print("Alrady has a Holder")
	end
end)

i am new to datastore tables and all im trying to remove the tool from datastore once it is deleted from the folder but it does not work. anything will be great TY.

3 comments

0

Saving data every time a child is added/removed can cause DataStore saving to exceed the allowed limit. You should instead save what you need saved/changed into a table only when the player leaves or does something important.

0

In your ChildAdded/Removed, you could instead change a table directly. That table then gets saved from the methods of my last comment.

0

it takes players hours to get enough money to buy a new tool and all it should be fine but i can still change it tho if you want and what do you mean save it directly?