Trying to save children of a folder in the player using DataStore

Hello, so i’m currently trying to save children of a folder inside the player but it wont work i don’t know whats wrong with my script the output don’t say any errors here it is:

local datastoreservice = game:GetService("DataStoreService")
local mydata2 = datastoreservice:GetDataStore("cooldata")

game.Players.PlayerAdded:Connect(function(player)
	
	local fodler = Instance.new("Folder",player)
	fodler.Name = "TestFolder"
	
	local mydata
	
	local success, errormsg = pcall(function()
		local mydata = mydata2:GetAsync(player.UserId)
	end)
	
	if mydata ~= nil then
		if mydata.TestFolder then
			for i, v in pairs(mydata.TestFolder) do
				local val = Instance.new("StringValue")
				val.Name = v
				val.Parent = fodler
			end
		end
	end
	
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local mydata = {}
	
	mydata.TestFolder = {}
	
	for i, v in pairs(player.TestFolder:GetChildren()) do
		table.insert(mydata.TestFolder, v.Name)
		print(v.Name)
	end
	local success, errormsg = pcall(function()
	    mydata2:SetAsync(player.UserId,mydata)
	end)
	
	if success then
		print("your data was saved")
	end
	
end)


Thank you!

1 Like

Sorry but what do you mean? (30 characters)

Maybe Parts of the script aren’t running. Try adding some print()'s to see which part doesn’t work.

i tried doing that but still not working

does this show up in the output?

yea (30 charactersssssssssssss)

Hmm… I don’t see anything wrong with the code. Sorry, I have no Idea how to fix this.

Okay thank you!!! (30 characters)