how would u rotate a folder of parts? i have this obby so i want it to continuously rotate these two parts from a folder but im not sure how to do it. i tried a for loop for getting the folder of parts but it only rotates one unfortunately. ty!
how would u rotate a folder of parts? i have this obby so i want it to continuously rotate these two parts from a folder but im not sure how to do it. i tried a for loop for getting the folder of parts but it only rotates one unfortunately. ty!
Do you want the two blue parts to rotate around the center part or just rotate on themselves?
If you want to rotate each model individually, you can loop through the folder and use the :PivotTo() function of a model to rotate them.
Example code:
local folder = workspace.cyl1
local cylinders = folder:GetChildren()
local runService = game:GetService("RunService")
local rotateIncrement = 0
for _,cylinder in pairs(cylinders) do
local originalPivot = cylinder:GetPivot()
local rotationAmount = 0
runService.Heartbeat:Connect(function(deltaTime)
rotationAmount += 0.01
local newCFrame = originalPivot*CFrame.Angles(0,rotationAmount,0)
--apply rotation
cylinder:PivotTo(newCFrame)
end)
end
This code works if you only need a visual effect.
But if you are making an obby (from what I can see) you should just weld all of the decorative parts to the primary part. Then use an align-position+align-orientation object to use physics to rotate instead of changing the cframe.
just like this but for multiple parts
hey kash,
thanks for the help man, that really helps me out a lot.
i actually have a primary part specifically for this situation so thats covered but i’ve never actually used align pos/orientation before, how would you do that so that u could target multiple cylinders?
You would first weld the extra parts to the primary part.
Then you can make a script to add align-positions/orientations like this:
local part = script.Parent
local runService = game:GetService("RunService")
local attachment = Instance.new("Attachment",part)
local alignPosition = Instance.new("AlignPosition",part)
local alignOrientation = Instance.new("AlignOrientation",part)
alignPosition.RigidityEnabled = true
alignPosition.Attachment0 = attachment
alignPosition.Mode = 0 --one attachment enum
alignOrientation.RigidityEnabled = true
alignOrientation.Attachment0 = attachment
alignOrientation.Mode = 0 --one attachment enum
--Position where the part already is
alignPosition.Position = part.Position
--Rotate to how the part already is
alignOrientation.CFrame = part.CFrame
--Rotate forever
local connection = runService.Stepped:Connect(function()
alignOrientation.CFrame *= CFrame.Angles(0,0.01,0)
end)
--If the part will ever be destroyed, disconnect the connection to save resources
part.Destroying:Connect(function()
connection:Disconnect()
end)
hey Kash,
thank u so much for ur help bro. i appreciate it a lot. your script works great on unanchored parts and i tried to use it on the primary part of my model which is anchored and unfortunately it doesnt work when it’s anchored.
i actually found a post by suphi that works for multiple parts and i managed to figure it out.
my solution was:
rs.Heartbeat:Connect(function(deltatime)
for i, child in ipairs(workspace:GetChildren()) do
if child.Name == "cylinder1" then
local pp = child.PrimaryPart
pp.CFrame *= CFrame.fromOrientation(0, 5 * deltatime, 0)
end
end
end)
link 2 post:
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.