Table from datastore turned into string

So basically i made a script that saves the inventory.
It worked in studio.
Then in roblox it didn’t.
And then in Studio it didn’t too and the error says attempt to iterate over a string value

the error is in local script line 19

This is the server script:

local InventoryD = DataStore:GetDataStore("Inv")
local HttpS = game:GetService("HttpService")

local DataStore = game:GetService("DataStoreService")
local Inv = DataStore:GetDataStore("InvL")


local R_INV = game.ReplicatedStorage.Inventory.Events:WaitForChild("Recieve_INV")
local Send_INV = game.ReplicatedStorage.Inventory.Events:WaitForChild("Send_INV")

local Inventory = { -- Example Player Inventory
	 	
}


game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder",plr)
	folder.Name = "Invent"
	

	local success,errorMessage = pcall(function()
		local data = Inv:GetAsync(plr.UserId)
		print(data)
		Invent = data
	end)
	
	if success then
		print("Data successfully loaded!")
	end
	if errorMessage then
		warn(errorMessage)
	end

	Send_INV:FireClient(plr, Invent)
	game.Players.PlayerRemoving:Connect(function(plr)
		Inv:SetAsync(plr.UserId, Inventory)
	end)

	game:BindToClose(function()
		for i,plr in pairs(game.Players:GetPlayers()) do
			Inv:SetAsync(plr.UserId, Inventory)
		end
	end)
end)


R_INV.OnServerEvent:Connect(function(plr, ID)

	local success,errorMessage = pcall(function()
		local data = Inv:GetAsync(plr.UserId)
		Invent = data
	end)
	
	table.insert(Invent, ID)
	Inv:SetAsync(plr.UserId, Inventory)

end)


Local script:

local R_INV = game.ReplicatedStorage.Inventory.Events:WaitForChild("Recieve_INV")
local InvItems = game.ReplicatedStorage.Inventory.Items
local ID = game.ReplicatedStorage.Inventory.Events:WaitForChild("ID")
local Players = game:GetService("Players")

local Weapons = script.Parent
local plr = game.Players.LocalPlayer

local PlayerInvGUI = plr.PlayerGui.Menu.Inventory.Holder.Main.Colletion.Collectionframe:WaitForChild("Weapons")

local PlayInv = {}

local DarkShotValue = 0
local AngelValue = 0

Send_INV.OnClientEvent:Connect(function(Inventory) --loads the inv to players client
	print(Inventory)
	for i,v in Inventory do -- here is the error
		print(v)
		if v == 30001 then
			
			
			for i, it in InvItems:GetChildren() do
				if it:IsA("Frame") then
					print("1")
					for i, chi in it:GetChildren() do
						if chi:IsA("IntValue") then

							if chi.Value == v then
								if table.find(PlayInv, chi.Value) then
									
									for i, G in PlayerInvGUI:GetChildren() do
										if G:IsA("Frame") then
											
											for i, E in G:GetChildren() do
												if E:IsA("IntValue") then
													
												
													if E.Value == v then
														AngelValue += 1
														G.Frame.Frame.Time.Text = AngelValue.."x"
														print(G)
														




													end
												end
											end	

										end	
									end
								else
									local Duplicate = chi.Parent:Clone()
									AngelValue += 1
									Duplicate.Parent = script.Parent
									table.insert(PlayInv, chi.Value)
									print("inserted")
								end
							
							
								

							end
						end
					end
				end
			end
		end
		if v == 10001 then
		
			for i, it in InvItems:GetChildren() do
				if it:IsA("Frame") then
					print("1")
					for i, chi in it:GetChildren() do
						if chi:IsA("IntValue") then

							if chi.Value == v then
								if table.find(PlayInv, chi.Value) then

									for i, G in PlayerInvGUI:GetChildren() do
										if G:IsA("Frame") then

											for i, E in G:GetChildren() do
												if E:IsA("IntValue") then


													if E.Value == v then
														DarkShotValue += 1
														G.Frame.Frame.Time.Text = DarkShotValue.."x"
														print(G)





													end
												end
											end	

										end	
									end
								else
									local Duplicate = chi.Parent:Clone()
									DarkShotValue += 1
									Duplicate.Parent = script.Parent
									table.insert(PlayInv, chi.Value)
									print("inserted")
								end




							end
						end
					end
				end
			end
			
		
		end
	end
	
end)

ID.Event:Connect(function(It_ID, player) --if a player bough an item
	print(It_ID)
	if It_ID == 30001 then



		for i, it in InvItems:GetChildren() do
			if it:IsA("Frame") then
				print("1")
				for i, chi in it:GetChildren() do
					if chi:IsA("IntValue") then

						if chi.Value == It_ID then
							if table.find(PlayInv, chi.Value) then

								for i, G in PlayerInvGUI:GetChildren() do
									if G:IsA("Frame") then

										for i, E in G:GetChildren() do
											if E:IsA("IntValue") then


												if E.Value == It_ID then
													AngelValue += 1
													G.Frame.Frame.Time.Text = AngelValue.."x"
													print(G)





												end
											end
										end	

									end	
								end
							else
								local Duplicate = chi.Parent:Clone()
								AngelValue += 1
								Duplicate.Parent = script.Parent
								table.insert(PlayInv, chi.Value)
								print("inserted")
							end




						end
					end
				end
			end
		end
	end 
	if It_ID == 10001 then

		for i, it in InvItems:GetChildren() do
			if it:IsA("Frame") then
				print("1")
				for i, chi in it:GetChildren() do
					if chi:IsA("IntValue") then

						if chi.Value == It_ID then
							if table.find(PlayInv, chi.Value) then

								for i, G in PlayerInvGUI:GetChildren() do
									if G:IsA("Frame") then

										for i, E in G:GetChildren() do
											if E:IsA("IntValue") then


												if E.Value == It_ID then
													DarkShotValue += 1
													G.Frame.Frame.Time.Text = DarkShotValue.."x"
													print(G)





												end
											end
										end	

									end	
								end
							else
								local Duplicate = chi.Parent:Clone()
								DarkShotValue += 1
								Duplicate.Parent = script.Parent
								table.insert(PlayInv, chi.Value)
								print("inserted")
							end




						end
					end
				end
			end
		end


	end
	print(It_ID)
	R_INV:FireServer(It_ID)
end)

Try these scripts. If they still don’t work, could you send the UI too as it needs me to create one to debug this:

New Server Script:

local DataStore = game:GetService("DataStoreService")
local InventoryD = DataStore:GetDataStore("Inv")
local HttpS = game:GetService("HttpService")
local Inv = DataStore:GetDataStore("InvL")


local R_INV = game.ReplicatedStorage.Inventory.Events:WaitForChild("Recieve_INV")
local Send_INV = game.ReplicatedStorage.Inventory.Events:WaitForChild("Send_INV")

local Inventory = { -- Example Player Inventory

}


game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder",plr)
	folder.Name = "Invent"


	local success,errorMessage = pcall(function()
		local data = Inv:GetAsync(plr.UserId)
		print(data)
		Invent = data
	end)

	if success then
		print("Data successfully loaded!")
	end
	if errorMessage then
		warn(errorMessage)
	end

	Send_INV:FireClient(plr, Invent)
	game.Players.PlayerRemoving:Connect(function(plr)
		Inv:SetAsync(plr.UserId, Inventory)
	end)

	game:BindToClose(function()
		for i,plr in pairs(game.Players:GetPlayers()) do
			Inv:SetAsync(plr.UserId, Inventory)
		end
	end)
end)


R_INV.OnServerEvent:Connect(function(plr, ID)

	local success,errorMessage = pcall(function()
		local data = Inv:GetAsync(plr.UserId)
		Invent = data
	end)

	table.insert(Invent, ID)
	Inv:SetAsync(plr.UserId, Inventory)

end)

New local script

local R_INV = game.ReplicatedStorage.Inventory.Events:WaitForChild("Recieve_INV")
local Send_INV = game.ReplicatedStorage.Inventory.Events:WaitForChild("Send_INV")
local InvItems = game.ReplicatedStorage.Inventory.Items
local ID = game.ReplicatedStorage.Inventory.Events:WaitForChild("ID")
local Players = game:GetService("Players")

local Weapons = script.Parent
local plr = game.Players.LocalPlayer

local PlayerInvGUI = plr.PlayerGui.Menu.Inventory.Holder.Main.Colletion.Collectionframe:WaitForChild("Weapons")

local PlayInv = {}

local DarkShotValue = 0
local AngelValue = 0

Send_INV.OnClientEvent:Connect(function(Inventory)
	print(Inventory)
	for i,v in Inventory do -- here is the error
		print(v)
		if v == 30001 then
			for i, it in InvItems:GetChildren() do
				if it:IsA("Frame") then
					print("1")
					for i, chi in it:GetChildren() do
						if chi:IsA("IntValue") then

							if chi.Value == v then
								if table.find(PlayInv, chi.Value) then

									for i, G in PlayerInvGUI:GetChildren() do
										if G:IsA("Frame") then

											for i, E in G:GetChildren() do
												if E:IsA("IntValue") then


													if E.Value == v then
														AngelValue += 1
														G.Frame.Frame.Time.Text = AngelValue.."x"
														print(G)
													end
												end
											end	

										end	
									end
								else
									local Duplicate = chi.Parent:Clone()
									AngelValue += 1
									Duplicate.Parent = script.Parent
									table.insert(PlayInv, chi.Value)
									print("inserted")
								end
							end
						end
					end
				end
			end
		end
		if v == 10001 then

			for i, it in InvItems:GetChildren() do
				if it:IsA("Frame") then
					print("1")
					for i, chi in it:GetChildren() do
						if chi:IsA("IntValue") then

							if chi.Value == v then
								if table.find(PlayInv, chi.Value) then

									for i, G in PlayerInvGUI:GetChildren() do
										if G:IsA("Frame") then

											for i, E in G:GetChildren() do
												if E:IsA("IntValue") then


													if E.Value == v then
														DarkShotValue += 1
														G.Frame.Frame.Time.Text = DarkShotValue.."x"
														print(G)
													end
												end
											end	

										end	
									end
								else
									local Duplicate = chi.Parent:Clone()
									DarkShotValue += 1
									Duplicate.Parent = script.Parent
									table.insert(PlayInv, chi.Value)
									print("inserted")
								end
							end
						end
					end
				end
			end


		end
	end

end)

ID.Event:Connect(function(It_ID, player) --if a player bough an item
	print(It_ID)
	if It_ID == 30001 then
		for i, it in InvItems:GetChildren() do
			if it:IsA("Frame") then
				print("1")
				for i, chi in it:GetChildren() do
					if chi:IsA("IntValue") then

						if chi.Value == It_ID then
							if table.find(PlayInv, chi.Value) then

								for i, G in PlayerInvGUI:GetChildren() do
									if G:IsA("Frame") then

										for i, E in G:GetChildren() do
											if E:IsA("IntValue") then


												if E.Value == It_ID then
													AngelValue += 1
													G.Frame.Frame.Time.Text = AngelValue.."x"
													print(G)
												end
											end
										end	

									end	
								end
							else
								local Duplicate = chi.Parent:Clone()
								AngelValue += 1
								Duplicate.Parent = script.Parent
								table.insert(PlayInv, chi.Value)
								print("inserted")
							end
						end
					end
				end
			end
		end
	end 
	if It_ID == 10001 then

		for i, it in InvItems:GetChildren() do
			if it:IsA("Frame") then
				print("1")
				for i, chi in it:GetChildren() do
					if chi:IsA("IntValue") then
						if chi.Value == It_ID then
							if table.find(PlayInv, chi.Value) then
								for i, G in PlayerInvGUI:GetChildren() do
									if G:IsA("Frame") then
										for i, E in G:GetChildren() do
											if E:IsA("IntValue") then
												if E.Value == It_ID then
													DarkShotValue += 1
													G.Frame.Frame.Time.Text = DarkShotValue.."x"
													print(G)
												end
											end
										end	

									end	
								end
							else
								local Duplicate = chi.Parent:Clone()
								DarkShotValue += 1
								Duplicate.Parent = script.Parent
								table.insert(PlayInv, chi.Value)
								print("inserted")
							end
						end
					end
				end
			end
		end


	end
	print(It_ID)
	R_INV:FireServer(It_ID)
end)
1 Like

alr i need to do get to my pc in 1.5h and ill send u

what did u change its to much code to see the difference

I can’t actually remember what I changed, There is so much there but I did change something because it’s printing that it loaded, but I just don’t have the UI for it so that’s the only thing showing as an error now. EDIT: When you get to your PC, Let me know if it doesn’t work and I’ll make another fix.

1 Like

alr i will send u my ui in 1.5h cuz i am still in school

GUI.rbxl (83.4 KB)

yea try it out

alr it workkssss

Thx for the help

No problem, Good luck with your game!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.