The 2 for loops that load "BoxData" and "UnitData" don't work, it prints G and H but it doesn't print anything in the 2 loops why??

local KillsData = game:GetService("DataStoreService"):GetDataStore("test16Kills") 
local MoneyData = game:GetService("DataStoreService"):GetDataStore("test16Money") 
local UnitData = game:GetService("DataStoreService"):GetDataStore("test16Units") 
local BoxData = game:GetService("DataStoreService"):GetDataStore("test16Units") 
local HasPlayed = game:GetService("DataStoreService"):GetDataStore("test16Played") 

game.Players.PlayerAdded:connect(function(plrjoining)
	wait(0.05)
	local success, message = pcall(function()
    	local PlayerKey = "user_"..plrjoining.userId
		local plrnew = false
		if HasPlayed:GetAsync(PlayerKey) == nil then
			print(plrjoining.Name.." is a new player!")
			plrnew = true
			local PlayerKey = "user_"..plrjoining.userId
			HasPlayed:SetAsync(PlayerKey, true)
		end
		local PlayerKey = "user_"..plrjoining.userId
		local data = game.ServerStorage.savefolder:Clone()
		data.Name = plrjoining.Name
		if plrnew == false then
			data.Kills.Value = KillsData:GetAsync(PlayerKey)
			data.Money.Value = MoneyData:GetAsync(PlayerKey)
			local units = UnitData:GetAsync(PlayerKey)
			print"G"
			for number, unit in pairs (units) do
				print"Q"
				local value = Instance.new("StringValue")
				value.Name = unit
				value.Value = unit
				value.Parent = data.Units
				print"W"
			end
			print"H"
			local boxes = BoxData:GetAsync(PlayerKey)
			for number2, box in pairs (boxes) do
				print"A"
				local value = Instance.new("StringValue")
				value.Name = box
				value.Value = box
				value.Parent = data.Boxes
				print"S"
			end
		elseif plrnew == true then
			data.Kills.Value = 0
			data.Money.Value = 0
			local units = {"Gun AI", "Tank AI"}
			for number, unit in pairs (units) do
				local value = Instance.new("StringValue")
				value.Name = unit
				value.Value = unit
				value.Parent = data.Units
			end
			local boxes = {"Box #1"}
			for number2, box in pairs (boxes) do
				local value = Instance.new("StringValue")
				value.Name = box
				value.Value = box
				value.Parent = data.Boxes
			end
		end
		data.Parent = game.ServerStorage.SAVEDDATA
	end)
	if not success then
	    print("An error occurred with loading "..plrjoining.Name.."'s data: "..message)
	end
end)

4 comments

1

My guess? units and boxes are empty. Check if they're nil at the same time as you print g and h

0

Nope they have stuff in them...

1

UnitData and BoxData are getting the same DataStore. I don't know if that's the problem, but it will give you incorrect data.

0

oh i see it now just one typo broke it all :/