This is an example of what I want to achieve:
How do I make a function that would automatically generate that, and have it centered at a given position?
This is an example of what I want to achieve:
How do I make a function that would automatically generate that, and have it centered at a given position?
are they made of frame?This text will be blurred
they are made of parts. not frames.
For the square grid of parts where the circle is, check the distance from center of the part to the center of the circle. If it’s less than the radius, make it “filled”.
-- Define variables
local model = script.Parent -- The model this script is placed in
local radius = 2 -- Replace with your desired radius
local offsetFromCenter = Vector3.new(0, 0, 0) -- Replace with the offset relative to the model's center
-- Calculate the center of the model
local function getModelCenter(model)
local totalPos = Vector3.new(0, 0, 0)
local count = 0
for _, part in pairs(model:GetChildren()) do
if part:IsA("BasePart") then
totalPos = totalPos + part.Position
count = count + 1
end
end
if count > 0 then
return totalPos / count
else
return model.PrimaryPart and model.PrimaryPart.Position or Vector3.new(0, 0, 0)
end
end
-- Function to light up parts within radius
local function lightUpPartsWithinRadius()
local center = getModelCenter(model)
local targetPosition = center + offsetFromCenter
for _, part in pairs(model:GetChildren()) do
if part:IsA("BasePart") then
local distance = (part.Position - targetPosition).magnitude
if distance <= radius then
-- Change part properties to make it appear lit up
part.BrickColor = BrickColor.new("Bright red") -- Example: Change color to red
part.Material = Enum.Material.Neon -- Example: Change material to neon
else
-- Optionally, reset properties for parts outside the radius
part.BrickColor = BrickColor.new("Bright blue") -- Example: Change color back
part.Material = Enum.Material.SmoothPlastic -- Example: Change material back
end
end
end
end
-- Call the function to light up parts
lightUpPartsWithinRadius()
That’s not what I want to make. I want to make block parts that create a circle, that center at a given position, with x size.
-- Settings
local center = Vector3.new(10, 20, 0) -- Center of the circle
local radius = 15 -- Radius of the circle
local partSize = Vector3.new(4, 1, 4) -- Size of each part
-- Create a function to make a part
local function createPart(position)
local part = Instance.new("Part")
part.Size = partSize
part.Position = position
part.Anchored = true
part.Parent = workspace
end
-- Determine the number of parts per row
local numPartsPerRow = math.ceil(2 * radius / partSize.X)
-- Create parts in a filled circle
for x = -numPartsPerRow, numPartsPerRow do
for z = -numPartsPerRow, numPartsPerRow do
-- Calculate the actual position
local posX = center.X + x * partSize.X
local posZ = center.Z + z * partSize.Z
-- Check if the position is within the circle
local distance = math.sqrt((posX - center.X)^2 + (posZ - center.Z)^2)
if distance <= radius then
local position = Vector3.new(posX, center.Y, posZ)
createPart(position)
end
end
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.