Could anyone tell me why some of my cloned assets arent parenting somtimes? These scripts are supposed to generate 3 blocks yet sometimes it only visibly shows 2 or even 1.
I also got an error once telling me ‘Parent was locked’ but idk how to fix this.
Module script (cropped):
function Round.blockMaker(coords: {string}) --Coord e.g "2 3" ("x y")
--Creates each tile
local block = Instance.new("Frame")
block.Name = "Block"
block.BackgroundColor3 = Color3.fromRGB(255, 115, 0)
block.BackgroundTransparency = 1
--Creates block size by calculating maximum boundaries
local x, y = 0, 0
for i,coord in pairs(coords) do
local tX, tY = unpack(string.split(coord, " "))
tX, tY = tonumber(tX), tonumber(tY)
if tX > x then
x = tX
end
if tY > y then
y = tY
end
end
block.Size = UDim2.new(0, 120*x, 0, 120*y)
--Creates an adjacent frame for each tile to create a shadow effect
local shadow = Instance.new("Frame")
shadow.Size = UDim2.new(1,0,1,0)
shadow.Name = "Shadow"
shadow.Position = UDim2.new(0,20,0,20)
shadow.BackgroundTransparency = 1
shadow.Parent = block
--Creates a block for each coordinate and clones into the shadow frame and block
for i, coord in pairs(coords) do
local tX, tY = unpack(string.split(coord, " "))
tX, tY = tonumber(tX), tonumber(tY)
--Creates shadows first
local miniShadow = Instance.new("Frame")
miniShadow.Name = coord
miniShadow.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
miniShadow.BackgroundTransparency = .75
miniShadow.Size = UDim2.new(1/x, 0, 1/y, 0)
miniShadow.Position = UDim2.new((tX-1)/x, 0, (tY-1)/y, 0)
miniShadow.Parent = shadow
--Creates Tole
local tile = miniShadow:Clone()
tile.BackgroundColor3 = Color3.fromRGB(255, 115, 0)
tile.BackgroundTransparency = 0
tile.BorderColor3 = Color3.fromRGB(255, 115, 0)
tile.BorderSizePixel = 2
rp.Assets.Shading:Clone().Parent = tile
tile.Parent = block
end
--Adds final touches to block and parents it to block folder
rp.Assets.UIDragDetector:Clone().Parent = block
local blockScript = rp.Assets.BlockScript:Clone()
blockScript.Parent = block
blockScript.Enabled = true
block.Parent = rp.Blocks
end
function Round.random(max)
return math.random(1, max)
end
function Round.generate(plr: Player, number: number?)
local blockNumber = number or 3
local max = #game.ReplicatedStorage.Blocks:GetChildren()
local blockTable = {}
for i, v in pairs(game.ReplicatedStorage.Blocks:GetChildren()) do
table.insert(blockTable, v)
end
local blocks = {}
for i = 1,blockNumber do
local block = blockTable[Round.random(max)]
table.insert(blocks, block)
block.Position = UDim2.new(0,200,0,200*i)
block.BlockScript.OriginalPos.Value = "0,200,0,"..(200*i)
end
rp.Events.GenerateBlocks:FireClient(plr, blocks)
--Irrelevant
local blocksSplit = {}
for i,v in pairs(blocks) do
local blockSplit2 = {}
for i,c in ipairs(v:GetChildren()) do
if c.Name ~= "Shadow" and c:IsA("Frame") then
table.insert(blockSplit2, c.Name)
end
end
table.insert(blocksSplit, blockSplit2)
end
return blocksSplit
end
Local script:
local rp = game.ReplicatedStorage
local gameUI = script.Parent.GameUi
rp.Events.GenerateBlocks.OnClientEvent:Connect(function(blocks)
task.wait()
for i,block in ipairs(blocks) do
block.Parent = gameUI.RoundFrame.Blocks
block.UIDragDetector.BoundingUI = gameUI.RoundFrame
end
end)