Hey! I was wondering how to make something like in the video I sent in this post. I know it probably has to do with CFrames, although, CFrames really arent my strong suit. If someone can help me out, or at least point me in the right direction I would be thankful!
Create a red cylinder, make sure it’s anchored, and rotate it like so:
local redCylinder = red cylinder goes here
local brownBall = brownBall goes here
redCylinder.Position = ball.Position -- positions the cylinder to the balls position
--about every 1/30th of a second, do the code inside this while loop:
while true do
wait()
--rotate the red cylinder 1 degree in each direction
redCylinder.CFrame = redCylinder.CFrame * CFrame.Angles(math.rad(1), math.rad(1), math.rad(1))
end
1 Like
You could just weld the parts together. This will also save on performance.
Why would it save performance?
There was an error within your script so I would only be able to do it to one sphere and not any others. I managed to fix this by simply grouping the objects and placing the script within each of them then I set the variables to the objects within the models.
Alright, cheers!
Another thing you can do is make every ball / sphere it’s own model and then group all of those ball / sphere models into a group.
Then you can do:
local ballModels = model that holds all of the balls should be linked here
function spinModel(model)
local redCylinder = model["NAME OF RED CYLINDER GOES HERE"]
local brownBall = model["NAME OF BROWN BALL GOES HERE"]
redCylinder.Position = ball.Position -- positions the cylinder to the balls position
--about every 1/30th of a second, do the code inside this while loop:
while true do
wait()
--rotate the red cylinder 1 degree in each direction
redCylinder.CFrame = redCylinder.CFrame * CFrame.Angles(math.rad(1), math.rad(1), math.rad(1))
end
end
--look at each item in the ball models group:
for _, item in pairs(ballModels:GetChildren())do
--if the item is one of the sphere models,
if item:IsA("Model") then
--rotate that sphere model:
coroutine.wrap(spinModel)(item)
end
end