local cyl = script.Parent
local roof = workspace.roof
local radius = 15
local numberofParts = 10
local tweenService = game:GetService("TweenService")
local nightTime = true
local function createLasers()
local laserparts = {}
for i = 1, numberofParts do
local angle = (math.pi * 2 / numberofParts) * i
local cylTop = cyl.Position + Vector3.new(0,cyl.Size / 2,0)
local roofBottom = roof.Position - Vector3.new(0,roof.Size / 2,0)
local laserPartHeight = (roofBottom.Y - cylTop.Y)
local x = radius * math.cos(angle)
local z = radius * math.sin(angle)
local laserPart = Instance.new("Part", cyl)
laserPart.Shape = Enum.PartType.Cylinder
laserPart.Anchored = true
laserPart.Name = "laserPart"
laserPart.Size = Vector3.new(laserPartHeight, .5 ,.5)
laserPart.Material = Enum.Material.Neon
laserPart.Color = Color3.new(1, 0.321569, 0.321569)
local position = cyl.Position + Vector3.new(x, cyl.Size.X / 2 + laserPart.Size.X / 2, z)
laserPart.CFrame = CFrame.new(position) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(90))
table.insert(laserparts, laserPart)
end
return laserparts
end
local function rotateLasers(laserparts)
end
local LaserParts = createLasers()
I would use a separate part and use it as the Pivot.
^ Assuming this is the pivot, you can add a BasePart onto the middle of the cylinder and set that in a Model as the PrimaryPart.
An easy way to rotate this would be to weld all of those lasers onto the pivot using a WeldConstraint, then write some code that rotates the pivot, then the lasers will follow.
If you DON’T want to use welds, then I would try using :PivotTo(), but I’m unsure if the lasers will follow your pivot.
Are you only going to use a fixed amount of lasers, or is it going to change due to variables in the game?
If it’s always going to be 10 lasers then you don’t need to do all the scripting.
Just create them in studio, place them around the beige Part as a Model, and CFrame the Model’s rotation. You could also tween them to the next laser’s position (just 36°), reset them back to 0°, and keep repeating after that.
i really shouldve done that in the first place. i just didnt think of it. thanks so much astro!! i ended up taking a longer route to get it done but oh well. cheers mate!!!
for any1 trying to do something like this, this is the script:
local cyl = script.Parent
local roof = workspace.roof
local radius = 15
local numberofParts = 10
local tweenService = game:GetService("TweenService")
local rs = game:GetService("RunService")
local nightTime = true
local cooldown = false
local function createLasers()
local laserparts = {}
local cylTop = cyl.Position + Vector3.new(0,cyl.Size / 2,0)
local roofBottom = roof.Position - Vector3.new(0,roof.Size / 2,0)
local laserPartHeight = (roofBottom.Y - cylTop.Y)
for i = 1, numberofParts do
local angle = (math.pi * 2 / numberofParts) * i
local x = radius * math.cos(angle)
local z = radius * math.sin(angle)
local laserPart = Instance.new("Part", cyl)
laserPart.Shape = Enum.PartType.Cylinder
laserPart.Anchored = true
laserPart.Name = "laserPart"
laserPart.Size = Vector3.new(laserPartHeight, .5 ,.5)
laserPart.Material = Enum.Material.Neon
laserPart.Color = Color3.new(1, 0.321569, 0.321569)
local position = cyl.Position + Vector3.new(x, cyl.Size.X / 2 + laserPart.Size.X / 2, z)
laserPart.CFrame = CFrame.new(position) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(90))
table.insert(laserparts, laserPart)
end
return laserparts, laserPartHeight
end
-- Function to rotate the lasers around the cylinder
local function rotateLasers(laserparts, laserpartHeight)
local time = tick()
local angle = time % (2 * math.pi) -- Ensure angle stays within 0 to 2*pi
for i, laserPart in ipairs(laserparts) do
local partAngle = (math.pi * 2 / numberofParts) * i
local x = radius * math.cos(partAngle + angle)
local z = radius * math.sin(partAngle + angle)
-- Position laser part on the circle around the cylinder base
local position = cyl.Position + Vector3.new(x, laserpartHeight / 2, z)
-- Update the laser part's position
laserPart.CFrame = CFrame.new(position) * CFrame.Angles(0, 0, math.rad(90))
end
end
local laserParts, laserPartHeight = createLasers()
-- Update the lasers' positions continuously
rs.Heartbeat:Connect(function()
rotateLasers(laserParts, laserPartHeight)
end)
local function giveLasersDamage(laserparts)
for _, laserpart in ipairs(laserparts) do
laserpart.Touched:Connect(function(hit)
local hum:Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
if not cooldown then
cooldown = true
hum:TakeDamage(30)
task.wait(.5)
cooldown = false
end
end
end)
end
end
giveLasersDamage(laserParts)
Oh god that’s a lot of effort.
10 cylinder laser Parts, welded to a center Part, with a HingeConstraint in it attached to either the white or black Parts, and you could change the AngularVelocity of the HingeConstraint to make it spin as fast as you want.