Why is this script letting me place the block, even if the one of the "cells" are "closed"?
By "closed", I mean that all the cells has an isOpen - value set to true, and when a block is placed on top of them, they are automatically set to false, so that I cannot place on those cells again, but it still lets me place the block(and yes, I have checked that the variables and that the isOpen - value is updated correctly)
Look further down on this question for images to see what actually happens.
My code is as follows:
----Placing the block----
Mouse.Button1Down:connect(function()
if Cooldown == false then
if ItemsLeft.Value > 0 then
ItemsLeft.Value = ItemsLeft.Value - 1
Cooldown = true
for i,x in ipairs(modelCells:GetChildren()) do
for i,v in pairs(TycoonCells:GetChildren()) do
if x.Name == v.cellPosHolder.cellPos.Value then
if v.isOpen.Value == true then --//This should, in my eyes, check if all of the cells are open, and if they are, you may place the block, but even if one of the cells are closed (i.e their / its isOpen.Value == false), the block still gets placed, why?
v.isOpen.Value = false
local new = cloneModel:clone()
new.Parent = ItemsPlacedFolder
BlockBox.Color3 = Color3.new(255,0,0)
for i,v in pairs(new:GetChildren()) do
if v:IsA("BasePart") then
if v.Name ~= "Cell" then
v.CanCollide = true
v.Transparency = 0
end
end
end
else
print("One of the cells is not open, please choose some other spot to place your item!") --//This should print when one or more of the "cells" have a value named "isOpen", and the value is true
end
end
end
end
end
end
----////Check if we have any of the item left.
if ItemsLeft.Value <= 0 then --//If we don't then...
BlockBox.Adornee = nil
BlockBox.Visible = false
cloneModel:Destroy()
Inventory.Visible = false
OpenCloseButton.Visible = true
for i,v in pairs(PlrGui:GetChildren()) do
if v.Name == "CellBox" then
local boxes = v
v.Visible = false
end
end
end
wait(0.05)
Cooldown = false
BlockBox.Color3 = Color3.new(0,255,0)
end)
Link to images:
Image 1 shows the cells.
Image 2 shows what it looks like when I have placed blocks inside of each other, which should not happen because the cells' isOpen value is set to false.
Image 3 shows when just 1 block is placed.
Image 4 shows my output.
