ServerScriptService.DataStore.ObjectsDataHandler:83: attempt to index nil with 'Objects'

This is probably the most perplexing problem I’ve had so far. For some context, I’m trying to basically get the area plot that was designated to the player and save the positions of the objects inside it so I’ll be able to load it back again when the player joins back. For some odd reason though, it keeps returning the error as seen in the title.

function PlayerAreaTracker(plr)	
	if plr then
		print(workspace.PlayerSpaces.AreasAvailable:GetChildren())
		for i, v in ipairs(workspace.PlayerSpaces.AreasAvailable:GetChildren()) do
			if workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(v)).PlayerName.Value == plr.Name then
				return v
			end
		end
	end
end
local function save(player)
local success, pdata
	local area = PlayerAreaTracker(player)
	local objs, data = {},{}
.
.
.

print(area) --nil
print(workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(area)).Objects:GetChildren()) --problem

	
	if area then
		if workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(area)).Objects:GetChildren() then
			for i,v in ipairs(workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(area)).Objects:GetChildren()) do
				table.insert(data, {
					v.Name,
					workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(area)).Grid.CFrame:ToObjectSpace(v.CFrame)
				})
				print(workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(area)).Grid.CFrame:ToObjectSpace(v.CFrame))
			end
		end
	end
.
.
.
--rest of code

Players.PlayerRemoving:Connect(save)
2 Likes

Fixed. Turns out it was because there was a PlayerRemoving event which was too quick that affected the code.

2 Likes

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