Data store doesn't work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to be able to load my tools in.

  2. What is the issue? The script saves but it doesn’t load.

  3. What solutions have you tried so far? I’ve looked at the developer forums multiple times. Changed my code completely and it still didn’t work.

-- loading
if CameraData then
		print("000")
		for _, v in pairs(CameraData) do
			print(111)
			if cameraFolder:FindFirstChild(v) then
				print("211")
				local kameraKlone = game.ServerStorage.Cameras[v]:Clone()
				kameraKlone.Parent = player.Backpack 
				print("Cameras loaded!")
			end
		end

	end
-- tool saves
game.Players.PlayerRemoving:Connect(function(player)
	local baccpacc = player:FindFirstChild("Backpack"):GetChildren()
	local Cameraz = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
	local CameraTable = {}
	for _,v in pairs(baccpacc)do
		table.insert(Cameraz,v.Name)
		print(707)
	end	
	wait()
	for _,v in pairs(Cameraz)do
		table.insert(CameraTable,v.Name)
		print(554)
	end		
	PDs:SetAsync(player.UserId.."-cam",CameraTable)	
	print("Cameras saved!")
end)

There are not errors unfortunately but the code doesn’t load in the game but it does in studio.

Did you make sure you enabled your games API Services setting

you never gave us the Player Added function or you never added one

I automatically guessed there was code above because you don’t seem CameraData defined in their script. So I guess it’s there, just above, also they said it loads in studio, just not the game. Also note they have a player variable, that would of errored.

Yes, I do have API enabled. Second, I do have a player added function its at the very top of the script.

Does it print both of these parts?

No it doesn’t print any of those.


	pcall(function()
		local CameraData = PDs:GetAsync(player.UserId.."-cam")
		if CameraData then
			print("000")
		for _, v in pairs(CameraData) do
			print(111)
			if cameraFolder:FindFirstChild(v) then
				print("211")
				local kameraKlone = game.ServerStorage.Cameras[v]:Clone()
					kameraKlone.Parent = player.StarterGear 
				print("Cameras loaded!")
				else
					warn("No data was sent, Error 554")
			end
			end
		else 
			warn("Cannot find data. Error 111")
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	pcall(function()
		local Cameraz = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
		local CameraTable = {}
		for _,v in pairs(player.StarterGear:GetChildren())do
			if v then
				table.insert(Cameraz,v.Name)
			end
			print(707)
		end	
		wait()
		for _,v in pairs(Cameraz)do
			if v then
				table.insert(CameraTable,v.Name)
			end
			print(554)
		end		
		PDs:SetAsync(player.UserId.."-cam",CameraTable)	
		print("Cameras saved!")
	end)
end)

I edited some of my code to see if it works and now it prints 111.

I’d check the camera folder in the studio explorer and see what names there are in there, then print out what v is to make sure it is checking for a valid name.

So now It doesn’t print anything it only prints “Cameras saved!” and 000 but nothing else will print.

Try removing the pcall temporarily while you test. If there are any error messages it will be suppressed by pcall.

If it only fails in Roblox: You can also see the output in Roblox, by pressing F9. Same output as in Studio including errors.

Even with out pcall it still prints nothing and tools still do not load.

Need the whole code, it’s ridiculous to speculate on something you could provide.
Also need to see your data structure (a pic of the “folders” and how you set it up)

Like cameraFolder … where did that come from, where is it aimed at.

-- Variables
local dss = game:GetService("DataStoreService")
local PDs = dss:GetDataStore("PetData")
local serverStorage = game:GetService("ServerStorage")
local cameraFolder = serverStorage:FindFirstChild("Cameras")
-- Equips
local function equipPet(player,pet)

	local char = player.Character

	if pet ~= nil and char ~= nil then

		if char:FindFirstChild(player.Name.."'s pet") then char[player.Name.."'s pet"]:destroy() end
		if char.HumanoidRootPart:FindFirstChild("AttachmentCharacter") then 
			char.HumanoidRootPart:FindFirstChild("AttachmentCharacter"):destroy()
		end
		pet.Name = player.Name.."'s pet"

		pet:SetPrimaryPartCFrame(char.HumanoidRootPart.CFrame)
		local modelSize = pet.PrimaryPart.Size
		local AttachmentChar = Instance.new("Attachment")
		AttachmentChar.Visible = false
		AttachmentChar.Name = "Attachment Character"
		AttachmentChar.Parent = char.HumanoidRootPart
		AttachmentChar.Position = Vector3.new(1,1,0) + modelSize

		local attachmentPet = Instance.new("Attachment")
		attachmentPet.Visible = false
		AttachmentChar.Name = "Attachment Pet"
		attachmentPet.Parent = pet.PrimaryPart

		local alignedPosition = Instance.new("AlignPosition")
		alignedPosition.MaxForce = 25000
		alignedPosition.Attachment0 = attachmentPet
		alignedPosition.Attachment1 = AttachmentChar
		alignedPosition.Responsiveness = 25
		alignedPosition.Parent = pet

		local alignedOrientation = Instance.new("AlignOrientation")
		alignedOrientation.MaxTorque = 25000
		alignedOrientation.Attachment0 = attachmentPet
		alignedOrientation.Attachment1 = AttachmentChar
		alignedOrientation.Responsiveness = 25
		alignedOrientation.Parent = pet

		pet.Parent = char
	end
end
-- leaderstats
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats" 
	leaderstats.Parent = player

	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 0
	Cash.Parent = leaderstats

	local Gems = Instance.new("IntValue")
	Gems.Name = "Gems"
	Gems.Value = 0
	Gems.Parent = leaderstats

	local Followers = Instance.new("NumberValue")
	Followers.Name = "Followers"
	Followers.Parent = leaderstats

	local inventory = Instance.new("Folder")
	inventory.Name = "PetInventory"
	inventory.Parent = player

	local equippedPets = Instance.new("StringValue")
	equippedPets.Name = "Equipped"
	equippedPets.Parent = player

	local dataFolder = Instance.new("Folder")
	dataFolder.Name = player.Name
	dataFolder.Parent = serverStorage.RemoteData

	local playerData = Instance.new("Folder")
	playerData.Name = player.Name
	playerData.Parent = serverStorage.PlayerData

	local cameraInventory = Instance.new("Folder")
	cameraInventory.Name = "Inventory"
	cameraInventory.Parent = playerData

	local Debounce = Instance.new("BoolValue")
	Debounce.Name = "Debounce"
	Debounce.Parent = dataFolder

	player.CharacterAdded:connect(function(Char)
		if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPets.Value) then
			equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPets.Value):Clone())

		end
	end)
	equippedPets.Changed:connect(function()
		if equippedPets.Value ~= nil then
			if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPets.Value) then
				equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPets.Value):Clone())
			end
		end
	end)

	local data = PDs:GetAsync(player.UserId.."-pet")

	if data then

		for i, petName in pairs(data) do
			if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(petName) then
				local Stringval = Instance.new("StringValue")
				Stringval.Name = petName
				Stringval.Parent = player.PetInventory
			end
		end

		game.ReplicatedStorage.SendData:FireClient(player,data)
	else
		print("No data detected.")
	end

	local equippedPetsData = PDs:GetAsync(player.UserId.."-equipped")
	local CoinsData = PDs:GetAsync(player.UserId.."-coins")
	local GemData = PDs:GetAsync(player.UserId.."-gems")
	local followerData = PDs:GetAsync(player.UserId.."-followers")
	--local CameraData = PDs:GetAsync(player.UserId.."-cam")
	local backpack = player:WaitForChild("Backpack")
	local staterGear = player:WaitForChild("StarterGear")
	
		local CameraData = PDs:GetAsync(player.UserId.."-cam")
		if CameraData then
			print("000")
		for _, v in pairs(CameraData) do
			print(111)
			if cameraFolder:FindFirstChild(v) then
				print("211")
				local kameraKlone = game.ServerStorage.Cameras[v]:Clone()
					kameraKlone.Parent = player.StarterGear 
				print("Cameras loaded!")
				else
					warn("No data was sent, Error 554")
			end
			end
		else 
			warn("Cannot find data. Error 111")
	end

	if CoinsData then
		Cash.Value = CoinsData
	end
	if followerData then
		Followers.Value = followerData
	end
	if GemData then
		Gems.Value = GemData
	end
	if equippedPetsData then
		equippedPets.Value = equippedPetsData
		game.ReplicatedStorage.SetEquippedPet:FireClient(player,equippedPetsData)
	end

end)
-- Saves
local function saveData(player)
	if player:FindFirstChild("PetInventory") then
		local Inventory = {}

		for i, v in pairs(player.PetInventory:GetChildren()) do
			table.insert(Inventory,v.Name)
		end
		local success, errorMsg = pcall(function()
			PDs:SetAsync(player.UserId.."-pet",Inventory)
		end)

		if success then
			print("Data Saved!")
		else
			print("Error: "..errorMsg)
		end
	end

	if player:FindFirstChild("Equipped") then
		if player.Equipped.Value ~= nil then
			print("1")
			local success, errorMsg = pcall(function()
				PDs:SetAsync(player.UserId.."-equipped",player.Equipped.Value)
				print("2")
			end)
		end
	end

	if player.leaderstats:FindFirstChild("Cash") then
		if player.leaderstats.Cash.Value ~= nil then
			local success, errorMsg = pcall(function()
				PDs:SetAsync(player.UserId.."-coins",player.leaderstats.Cash.Value)
			end)
		end
	end

	if player.leaderstats:FindFirstChild("Followers") then
		if player.leaderstats.Followers.Value ~= nil then
			local success, errorMsg = pcall(function()
				PDs:SetAsync(player.UserId.."-followers",player.leaderstats.Followers.Value)
			end)
		end
	end
	if player.leaderstats:FindFirstChild("Gems") then
		if player.leaderstats.Gems.Value ~= nil then
			local success, errorMsg = pcall(function()
				PDs:SetAsync(player.UserId.."-gems",player.leaderstats.Gems.Value)
			end)
		end
	end
end
-- tool saves
game.Players.PlayerRemoving:Connect(function(player)
		local Cameraz = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
		local CameraTable = {}
		for _,v in pairs(player.StarterGear:GetChildren())do
			if v then
				table.insert(Cameraz,v.Name)
				print(707)

			end
		end	
		wait()
		for _,v in pairs(Cameraz)do
			if v then
				print(v)
				table.insert(CameraTable,v.Name)
				print(554)
			end
		end		
		PDs:SetAsync(player.UserId.."-cam",CameraTable)	
		print("Cameras saved!")
end)
-- saves incase servers fail
game:BindToClose(function()
	for i, player in pairs(game.Players:GetPlayers()) do
		saveData(player)
	end
end)
-- more equip stuff
game.ReplicatedStorage.EquippedPet.OnServerEvent:connect(function(player,petName)
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.Equipped.Value = petName
	end
end)
game.ReplicatedStorage.UnEquippedPet.OnServerEvent:connect(function(player)
	player.Equipped.Value = ""
	if player.char:FindFirstChild(player.Name.."'s pet") then
		player.char[player.Name.."'s pet"]:destroy()
	end
	if player.char.HumanoidRootPart:FindFirstChild("AttachmentChar") then
		player.char.HumanoidRootPart:FindFirstChild("AttachmentChar"):Destroy()
	end
end)

sss

Still missing major chucks of whatever you have going on.
lost me here …

for _, v in pairs(CameraData) do
			print("111")
			if cameraFolder:FindFirstChild(v) then
				print("211")
				local kameraKlone = game.ServerStorage.Cameras[v]:Clone()
				kameraKlone.Parent = player.StarterGear 
				print("Cameras loaded!")
			else
				warn("No data was sent, Error 554")
			end
		end

I’ll need to have/know what that is to test anything.
This isn’t a question I myself can answer without looking right at the whole program. However I do recognize where this came from and do have it and a working script. You’ll have to provide all you added and what you took away and where …

What I sent above was all the code.

The version I got of this works fine … You’ll have to step back a few versions and build slower. Testing as you go. Were you ever able to get this running via server … You’ll need to go back to that point. Like I said it lost me at kameraKlone. It’s looking for something in there… ?

I fixed it I just needed to re write the code in a different script.

I was looking at that program a bit and I may know what happen to you.
I have a Plugin called DataStore Editor (701506235). One thing it can do is clear old data or entire keys. This is very useful working with that code as you can remove the pet key and restart fresh. There’s a bug in there someplace …