I really don’t understand the problem that’s happening it’s like when I was setting a variable to another variable it doesn’t set the variable to the value of the other variable but at his reference …
Here the code :
local TestSelectedParts = {}
local function GetSelectedParts()
local Target = Mouse.Target
local Parts = TestSelectedParts
for v, Part in pairs(workspace:GetDescendants()) do
if Part:IsA("BasePart") then
local Position, Visible = Camera:WorldToViewportPoint(Part.Position)
if Part:FindFirstChild("SelectionBox") and Visible and math.sign(math.sign(Position.X - Mouse.X) * math.sign(Position.X - Origin.X) + math.sign(Position.Y - (Mouse.Y + 36)) * math.sign(Position.Y - Origin.Y)) == -1 then
table.insert(Parts, Part) --Here it change TestSelectedParts value and Parts value too
end
end
end
return Parts
end
You would probably have to copy all the elements from the TestSelectedParts table into the Parts table, as setting one table to another table will simply “point” to that table, instead of copying all the elements.
You could probably achieve this through a loop which goes through all the elements in the TestSelectedParts table and inserts it in the Parts table.
local function GetSelectedParts()
local Target = Mouse.Target
local Parts = table.move(LastSelectedParts, 1, #LastSelectedParts, 1, {})
table.insert(Parts, Target:FindFirstChild("SelectionBox") and Target or nil)
for v, Part in pairs(workspace:GetDescendants()) do
if Part:IsA("BasePart") then
local Position, Visible = Camera:WorldToViewportPoint(Part.Position)
if Part:FindFirstChild("SelectionBox") and Visible and math.sign(math.sign(Position.X - Mouse.X) * math.sign(Position.X - Origin.X) + math.sign(Position.Y - (Mouse.Y + 36)) * math.sign(Position.Y - Origin.Y)) == -1 then
table.insert(Parts, Part)
end
end
end
return Parts
end
Basically I only move all my table to the other table !