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?
I didn't remake your script but I can help you with checking if there is a part in that location
function CheckPos(pos) for _,x in pairs(game.Workspace.Blocks:GetChildren()) do if x:IsA("Part") then if x.Position == pos then return true --Block is there else return false --No block there end end end end
if YOUR_PART.Position ~= Vector3.new(POSITION) then --create part else --there is already a part in that position end
local mathX = math.random(100, 200) -- the two numbers are the position you want to generate between
local mathZ = math.random(100, 200)
newPos = Vector3.new(mathX, 200, mathZ)