A error i cant seem to figure out ("intermediate")

Yes! I got access to forum posting and replying. Now i my question can finally be answered! I’ll try to keep my first post as good and as clean as possible.

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

  1. What do you want to achieve? Keep it simple and clear!
    I have two errors i want to fix.

  2. What is the issue? Include screenshots / videos if possible!
    I have a furniture placement system, and when i place something, it errors with “ServerStorage.PlayerData.hasanchik:85: attempt to index number with ‘RedCube’” the furniture placement system is a good module, namely zblox164’s placementsystem v3 and it does wonders. There is nothing wrong with that module, but the serverscript placement handler errors with the previous error mentioned, although that uses my playerdata module.

and "Players.hasanchik.PlayerGui.MainGui.Frame.ShopFrame.ScrollingFrame.ShopHandler:149: attempt to index nil with ‘X’ " which is a error from my shophandler.

The first error i have never seen, so i cant and dont know how to fix it. The second error errors because the data isnt simply there, i think.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried googeling it multiple times in multiple ways, looking at the devforum, scriptinghelpers, but they all were similair but unrelated issues.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Error 1: ServerStorage.PlayerData.hasanchik:85: attempt to index number with ‘RedCube’

Error 2:layers.hasanchik.PlayerGui.MainGui.Frame.ShopFrame.ScrollingFrame.ShopHandler:149: attempt to index nil with ‘X’

The ServerStorage.PlayerData.hasanchik script: (This is a modulescript that changes name and copies itself for every player in the game, and then parents itself to ServerStorage.PlayerData. )
It errors on line 85.

local module = {}
local defaultTable = {
	["successLoading"] = true,

	["tokens"] = 0,

	["lastTimeObby"] = 1,

	["settings"] = {
		["music"] = true
	},

	["furniture"] = {},
	["materials"] = {},
	["colors"] = {},
	["effects"] = {},
	["death effects"] = {},
}
local plrData = defaultTable

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local HttpService = game:GetService("HttpService")
local DataStore2 = require(ReplicatedStorage.Modules.DataStore2)

local UpdateTokens = ReplicatedStorage:WaitForChild("UpdateTokens")
local ChangeData = ReplicatedStorage:WaitForChild("ChangeData")
local ReturnInfo = ReplicatedStorage:WaitForChild("ReturnInfo")
local BuyItem = ReplicatedStorage:WaitForChild("BuyItem")

a = script.FurnitureData.Value
local FurnitureData = require(a)

plr = game.Players:FindFirstChild(script.Name)
if plr then --You better not be using this module other than returning!
	data = DataStore2("data",plr)
end

function clear()
	local userId = plr.UserId
	local name = "data"
	local orderedDataStore = DataStoreService:GetOrderedDataStore(name .. "/" .. userId)
	local dataStore = DataStoreService:GetDataStore(name .. "/" .. userId)

	while true do
		local pages = orderedDataStore:GetSortedAsync(false, 100)
		local data = pages:GetCurrentPage()
		for _, pair in pairs(data) do
			print(("key: %d"):format(pair.key))
			dataStore:RemoveAsync(pair.key)
			orderedDataStore:RemoveAsync(pair.key)
		end
		if pages.IsFinished then
			print(("finished (%d: %s)"):format(userId, name))
			return
		end
	end
end

function save(a)
	if a then
		--local data2 = HttpService:JSONEncode({["tokens"] = 0})
		clear()
		plrData = defaultTable
		data:Set(plrData)
		UpdateTokens:FireClient(plr, plrData["tokens"])
	else
		--local data2 = HttpService:JSONEncode(plrData)
 		data:Set(plrData)
	end
end

function module.Load(m)
	plrData = m
	for i, v in pairs(defaultTable) do
		if not plrData[i] then
			plrData[i] = v
		end
	end
end

function module.Data(index, value, index2, index3, index4)
	plrData[index] = value
	if index4 then
		plrData[index][index2][index3][index4] = value
	elseif index3 then
		plrData[index][index2][index3] = value
	elseif index2 then
		plrData[index][index2] = value
	end
	if index == "tokens" then
		UpdateTokens:FireClient(plr, plrData["tokens"])
	end
	save()
end

function module.DataMath(index, value, symbol)
		if symbol == "+" then
			plrData[index] = plrData[index] + value
		elseif symbol == "-" then
			plrData[index] = plrData[index] - value
		elseif symbol == "/" then
			plrData[index] = plrData[index] / value
		elseif symbol == "*" then
			plrData[index] = plrData[index] * value
		end
		if index == "tokens" then
			UpdateTokens:FireClient(plr, plrData["tokens"])
		end
		save()
end

function module.ReturnData()
	return plrData
end

function module.ReturnDefault()
	return defaultTable
end

ChangeData.OnServerEvent:Connect(function(plr, setting1, value2, value)
	if plr.Name == script.Name then
		if setting1 == "settings" then
			plrData["settings"][value2] = value
			save()
		elseif setting1 == "erase" then
			save(true)
		elseif setting1 == "equip" then
			plrData["furniture"][value2][1] = value
			save()
		end
	end
end)

function OnReturnSettings() --Seperate function for returning settings, dont want client to see their playerdata
	return {plrData["settings"], plrData["furniture"], plrData["materials"], plrData["colors"], plrData["effects"], plrData["death effects"]}
end

ReturnInfo.OnServerInvoke = OnReturnSettings

function BuyItemFunc(plr, item, name) 
	if plr.Name == script.Name then
		local success = false
		local cost = item[1]
		if plrData["tokens"] >= cost and not plrData["furniture"][item[2]] then
			success = true
			plrData["tokens"] = plrData["tokens"] - cost
			plrData["furniture"][name] = {"unequipped", {0,0,0}, {0,0,0}}
		end
		UpdateTokens:FireClient(plr, plrData["tokens"])
		save()
		return success
	end
end


BuyItem.OnServerInvoke = BuyItemFunc

return module

The serversided placement handler: (The one that uses my playerdata script. For more info, it uses datastore 2 so i cant use Vector.new or datastore2 will error. I have to assign every X Y and Z their own value in a table. )
It errors on line 84, and all the similair lines after that.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local folder = game.ServerStorage.PlayerData
local DataStore2 = require(ReplicatedStorage.Modules.DataStore2)

-- Ignore the top three functions

-- Credit EgoMoose
local function checkHitbox(character, object)
	if object then
		local collided = false

		local collisionPoint = object.PrimaryPart.Touched:Connect(function() end)
		local collisionPoints = object.PrimaryPart:GetTouchingParts()

		for i = 1, #collisionPoints do
			if not collisionPoints[i]:IsDescendantOf(object) and not collisionPoints[i]:IsDescendantOf(character) then
				collided = true

				break
			end
		end

		collisionPoint:Disconnect()

		return collided
	end
end

local function checkBoundaries(plot, primary)
	local lowerXBound
	local upperXBound

	local lowerZBound
	local upperZBound

	local currentPos = primary.Position

	lowerXBound = plot.Position.X - (plot.Size.X*0.5) 
	upperXBound = plot.Position.X + (plot.Size.X*0.5)

	lowerZBound = plot.Position.Z - (plot.Size.Z*0.5)	
	upperZBound = plot.Position.Z + (plot.Size.Z*0.5)

	return currentPos.X > upperXBound or currentPos.X < lowerXBound or currentPos.Z > upperZBound or currentPos.Z < lowerZBound
end

local function handleCollisions(char, item, c)
	if c then
		if not checkHitbox(char, item) then
			item.PrimaryPart.Transparency = 1

			return true
		else
			item:Destroy()

			return false
		end
	else
		item.PrimaryPart.Transparency = 1

		return true
	end
end

--Ignore above

local function place(plr, name, location, prefabs, cframe, c, plot)
	local dataPlrModule = folder:FindFirstChild(plr.Name)
	local req = require(dataPlrModule)
	--print(playerData)
	
	local item = prefabs:FindFirstChild(name):Clone()
	item.PrimaryPart.CanCollide = false
	item:PivotTo(cframe)

	if plot and dataPlrModule then
		if checkBoundaries(plot, item.PrimaryPart) then
			return
		end

		item.Parent = location
		local offset = workspace.HouseShow.Plate.Position
		
		req.Data("furniture", item.PrimaryPart.Position.X-offset.X, name, "pos", "X")
		req.Data("furniture", item.PrimaryPart.Position.Y-offset.Y, name, "pos", "Y")
		req.Data("furniture", item.PrimaryPart.Position.Z-offset.Z, name, "pos", "Z")
		
		req.Data("furniture", item.PrimaryPart.Orientation.X, name, "ori", "X")
		req.Data("furniture", item.PrimaryPart.Orientation.Y, name, "ori", "Y")
		req.Data("furniture", item.PrimaryPart.Orientation.Z, name, "ori", "Z")
		
		local calc = handleCollisions(plr.Character, item, c)
		item:Destroy()
		return calc
	else
		local calc = handleCollisions(plr.Character, item, c)
		item:Destroy()
		return calc
	end
end

ReplicatedStorage.RequestPlacement.OnServerInvoke = place

The shophandler script, its a localscript: (errors on line 149)

wait(0.1)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

local BuyItem = ReplicatedStorage:WaitForChild("BuyItem")
local ReturnInfo = ReplicatedStorage:WaitForChild("ReturnInfo")
local ChangeData = ReplicatedStorage:WaitForChild("ChangeData")
local RequestPlacement = ReplicatedStorage:WaitForChild("RequestPlacement")
local DataStore2 = require(ReplicatedStorage.Modules.DataStore2)

local furnitureData = ReturnInfo:InvokeServer()[2]
local frame = script.Parent.Parent
local itemInfo = require(script.FurnitureData)
local itemInfo2 = itemInfo.ReturnData()

local player = Players.LocalPlayer
local mouse = player:GetMouse()

local equip = script.Parent.Parent.Equip
local buy = script.Parent.Parent.Buy
local button = script.Parent.Parent.Parent.HouseButton
local db = true
local opened = true

local frame = script.Parent.Parent
local scrollingFrame = frame.ScrollingFrame
local startingPos = frame.Position
local downPos = startingPos + UDim2.new(0,0, 0, 1000)
frame.Position = downPos
local waitt = 0.5

local placementModule = require(game.ReplicatedStorage.Modules:FindFirstChild("PlacementModuleV3"))
local placementInfo = placementModule.new(
	1,
	ReplicatedStorage.Furniture,
	Enum.KeyCode.R, nil, Enum.KeyCode.Q, Enum.KeyCode.E,
	Enum.KeyCode.ButtonR1, Enum.KeyCode.ButtonX, Enum.KeyCode.DPadUp, Enum.KeyCode.DPadDown
)
local plr = game.Players.LocalPlayer

placementModule:editAttribute("FloorStep", 1) 
placementModule:editAttribute("EnableFloors", true) 
placementModule:editAttribute("RotationStep", 45)

local show = workspace.HouseShow
local c = workspace.Houses.HouseT9:Clone()
c.Parent = show
c:PivotTo(show.Plate.CFrame)

local lastestSelected 

for i, v in pairs(script.Parent:GetChildren()) do
	if v.Name == "Item" then
		local viewPort = v.ViewportFrame
		local ItemInFrame = viewPort:GetChildren()[1]
		local bought = itemInfo2[ItemInFrame.Name]
		
		if bought then
			v.ImageColor3 = Color3.fromRGB(v.ImageColor3.R + 20, v.ImageColor3.G + 20 , v.ImageColor3.B + 20 )
		end
		v.Select.Activated:Connect(function()		
			furnitureData = ReturnInfo:InvokeServer()[2]
			local bought = furnitureData[ItemInFrame.Name]
			local item = itemInfo2[ItemInFrame.Name]
			lastestSelected = v
			frame.Info.Text = "Cost = "..item[1]
			equip.TextLabel.Text = "Equip"
			if not bought then
				buy.TextLabel.Text = 'Buy "'..item[2]..'"'
			else
				buy.TextLabel.Text = '"'..item[2]..'" Bought'
				if bought[1] == "equipped" then
					equip.TextLabel.Text = "Unequip"
				elseif bought[1] == "unequipped" then
					equip.TextLabel.Text = "Equip"
				end
			end
		end)
	end
end

buy.Activated:Connect(function()
	if lastestSelected then
		local viewPort = lastestSelected.ViewportFrame
		local ItemInFrame = viewPort:GetChildren()[1]
		local item = itemInfo2[ItemInFrame.Name]
		local success = BuyItem:InvokeServer(item, ItemInFrame.Name)
		if success then
			lastestSelected.ImageColor3 = Color3.fromRGB(lastestSelected.ImageColor3.R + 20, lastestSelected.ImageColor3.G + 20 , lastestSelected.ImageColor3.B + 20 )
			script.Parent.Parent.Buy.TextLabel.Text = '"'..item[2]..'" Bought'
		end
	end
end)

equip.Activated:Connect(function()
	if lastestSelected then
		local viewPort = lastestSelected.ViewportFrame
		local ItemInFrame = viewPort:GetChildren()[1]
		--for i = 1, 2 do --??????????
		furnitureData = ReturnInfo:InvokeServer()[2]
		local bought = furnitureData[ItemInFrame.Name]
		print(ItemInFrame.Name)
		print(furnitureData)
		if bought then
			if bought and bought[1] == "unequipped" then
				equip.TextLabel.Text = "Unequip"
				ChangeData:FireServer("equip", ItemInFrame.Name, "equipped")
				placementInfo:activate(ItemInFrame.Name, workspace.HouseShow.Plate.itemHolder, workspace.HouseShow.Plate, false, false, false)
			elseif bought[1] == "equipped" then
				equip.TextLabel.Text = "Equip"
				ChangeData:FireServer("equip", ItemInFrame.Name, "unequipped")
			end
		end
	end
end)

mouse.Button1Down:Connect(function()
	placementInfo:requestPlacement(RequestPlacement)
	placementInfo:terminate()
end)

button.Activated:Connect(function()
	if db then
		db = false
		if opened then
			frame:TweenPosition(startingPos, Enum.EasingDirection.Out, Enum.EasingStyle.Quint, waitt)
		elseif not opened then
			frame:TweenPosition(downPos, Enum.EasingDirection.In, Enum.EasingStyle.Quint, waitt)
		end 
		wait(waitt)
		opened = not opened
		db = true
	end
end)

while wait(1) do
	if plr then
		for i, v in pairs(show:GetChildren())  do
			if v.Name ~= "Plate" and v.Name ~= "Part" and v.Name ~= "SpawnLocation" and v.Name ~= "HouseT9" then
				v:Destroy()
			end
		end
		local furnitureData = ReturnInfo:InvokeServer()[2]
		for i2, v2 in pairs(furnitureData) do
			if v2[1] == "equipped" then
				local furniture = ReplicatedStorage.Furniture:FindFirstChild(i2):Clone()
				if furniture then
					furniture:SetPrimaryPartCFrame(CFrame.new(v2["pos"]["X"],v2["pos"]["Y"],v2["pos"]["Z"])*CFrame.Angles(math.rad(v2["ori"]["X"]),math.rad(v2["ori"]["Y"]),math.rad(v2["ori"]["Z"]))+show.Plate.Position)
					furniture.Parent = show
					furniture.PrimaryPart.Anchored = true
				end
			end
		end
	end
end

THe last part is unbearable to write because of the weird amount of lag. Now at this time i’m writing this it takes seconds for my words to appear. How do i fix this???

After a little testing, it seems that you cant even do a[b][c][d] = e.
This is very dumb, am i doing something wrong?

This little script here errors with the same error message.

local a = "1"
local b = "2"
local c = "3"
local d = "hi"
local e = {}
e[a][b][c] = d
print(e[a][b][c])

EDIT: After even more testing, i found a super hacky way for the error: (i replaced the repeating part)

		local returnData = req.ReturnData()
		local furniture = returnData["furniture"]
		furniture[name] = {"equipped", 
			["pos"] = {item.PrimaryPart.Position.X-offset.X, item.PrimaryPart.Position.Y-offset.Y, item.PrimaryPart.Position.Z-offset.Z}, 
			["ori"] = {item.PrimaryPart.Orientation.X, item.PrimaryPart.Orientation.Y, item.PrimaryPart.Orientation.Z}}
		req.Data("furniture", furniture)

But even THIS doesnt work. Now its just
image
Which is super confusing. There are even more errors than before! If ANYONE knows the answer to this question, please help me. I’m getting more frustrated by the second.

I fixed the issue by changing the playerdata datastore directly:

	local rawPlayerData = DataStore2("data",plr)
	local playerData = rawPlayerData:Get()
	
	local item = prefabs:FindFirstChild(name):Clone()
	item.PrimaryPart.CanCollide = false
	item:PivotTo(cframe)

	if plot and dataPlrModule then
		if checkBoundaries(plot, item.PrimaryPart) then
			return
		end

		item.Parent = location
		local offset = workspace.HouseShow.Plate.Position
		
		local returnData = req.ReturnData()
		
		playerData["furniture"][name][2][1] = item.PrimaryPart.Position.X-offset.X
		playerData["furniture"][name][2][2] = item.PrimaryPart.Position.Y-offset.Y
		playerData["furniture"][name][2][3] = item.PrimaryPart.Position.Z-offset.Z
		
		playerData["furniture"][name][3][1] = item.PrimaryPart.Orientation.X
		playerData["furniture"][name][3][2] = item.PrimaryPart.Orientation.Y
		playerData["furniture"][name][3][3] = item.PrimaryPart.Orientation.Z

I’m still very confused about this…