I've tried to figure this out for a while now and just can't find the error. There is a comment above the line of code that triggers the error. Basically I'm trying to store the position data within a table (whenever the player clicks on certain parts) that can be quickly accessed for later use (I have no need to sort the data, and the data is only ever used for comparison purposes). Here are some code snippets that affect what I'm trying to do:
local player = game:GetService("Players").LocalPlayer
local equipped = false
local depressStopped = false
local part = ""
local mouse = player:GetMouse()
local distance = 0
local tool = script.Parent
local copy = ""
local copyPosition = ""
local copyPositionX = game.Workspace.Parttay.Position.X
local copyPositionY = game.Workspace.Parttay.Position.Y
local copyPositionZ = game.Workspace.Parttay.Position.Z
local masterTable = {
[copyPositionX] = {[copyPositionY] = {[copyPositionZ]={copyPositionZ}}}
}
--[[TABLE LAYOUT: with example data
masterTable copyPositionX copyPositionY copyPositionZ
200 150 200 =200x150y200z
100 200 =200x100y200z
300 150 200 =300x150y200z
400 100 150 =400x100y150z
*note: the only data that can be directly accessed is the copyPositionZ
--]]
tool.Equipped:connect(function()
equipped = true
while equipped do
pcall(function()
distance = (mouse.Target.Position - game.Workspace[player.Name].Head.Position).magnitude
if mouse.Target:IsDescendantOf(game.Workspace.ConstantBlocks) and distance < 20 then
part = mouse.Target
position = part.Position
--other code
end
end)
end
end)
tool.Unequipped:Connect(function()
equipped = false
end)
mouse.Button1Up:connect(function()
depressStopped = true
end)
mouse.Button1Down:connect(function()
while equipped == true and depressStopped == false do
if part:IsDescendantOf(game.Workspace.ConstantBlocks) and distance < 20 then
--part comes from the equipped function
copyPositionX = part.Position.X
copyPositionY = part.Position.Y
copyPositionZ = part.Position.Z
print(copyPositionX, copyPositionY, copyPositionZ)
--THE FOLLOWING LINE CAUSES THE ERROR!
masterTable[copyPositionX][copyPositionY][copyPositionZ] = copyPositionZ
--other code
end
end
depressStopped = false
end)
I'm still kinda new to this and would appreciate any pointers as well!
[EDIT]
I may just misunderstand how it works, but this code works just fine:
part = game.Workspace.Parttay
copyPositionX = part.Position.X
copyPositionY = part.Position.Y
copyPositionZ = 0
print(copyPositionX, copyPositionY, copyPositionZ)
local masterTable = {
[copyPositionX] = {[copyPositionY] = {[copyPositionZ] = {copyPositionZ}}}
}
masterTable[copyPositionX][copyPositionY][copyPositionZ] = copyPositionZ
print(masterTable[copyPositionX][copyPositionY][copyPositionZ])

3 comments
First of all you should get rid of those dots in empty lines
That's to show there is more code, but I can separate the code snippets if it makes it easier.
I wasn't sure if this was a simple error on my part or not, so I didn't have every variable declared in the snippets. I just added all of them, I really am stumped on this though.