Hey, currently working on a script that would generate parts in different specific locations if a part is pressed. It probably didn't make much sense, so I will just show you the script:
for i,v in pairs(game.Workspace.Blocks:GetChildren()) do
v.ClickDetector.MouseClick:Connect(function()
v.Transparency = 0
v.CanCollide = true
local newPart = Instance.new("Part")
Instance.new("ClickDetector",newPart)
local newPos = Vector3.new(v.Position.X,v.Position.Y,v.Position.Z+2)
newPart.Position = newPos
newPart.TopSurface = "Smooth"
newPart.Size = Vector3.new(4, 2, 2)
newPart.Transparency = 0.6
newPart.CanCollide = false
newPart.Anchored = true
newPart.Parent = game.Workspace.Blocks
newPart.ClickDetector.MouseClick:Connect(function()
newPart.Transparency = 0
newPart.CanCollide = true
end)
local newPart = Instance.new("Part")
Instance.new("ClickDetector",newPart)
local newPos = Vector3.new(v.Position.X,v.Position.Y+2,v.Position.Z)
newPart.Position = newPos
newPart.TopSurface = "Smooth"
newPart.Size = Vector3.new(4, 2, 2)
newPart.Transparency = 0.6
newPart.CanCollide = false
newPart.Anchored = true
newPart.Parent = game.Workspace.Blocks
newPart.ClickDetector.MouseClick:Connect(function()
newPart.Transparency = 0
newPart.CanCollide = true
end)
local newPart = Instance.new("Part")
Instance.new("ClickDetector",newPart)
local newPos = Vector3.new(v.Position.X-4,v.Position.Y,v.Position.Z)
newPart.Position = newPos
newPart.TopSurface = "Smooth"
newPart.Size = Vector3.new(4, 2, 2)
newPart.Transparency = 0.6
newPart.CanCollide = false
newPart.Anchored = true
newPart.Parent = game.Workspace.Blocks
newPart.ClickDetector.MouseClick:Connect(function()
newPart.Transparency = 0
newPart.CanCollide = true
end)
end)
end
Basically, very easy, but I want to make it so the script wouldn't generate a part, if there is already a part in that location. Any ideas?

1 comment
I would recommend using math.random to generate a random position