Make planets spin on orbit

I’m trying to make planets spin in orbit but I don’t know why it’s not working.

Currently using a script that I didn’t make from another devforum post since I don’t know how orbiting works.

local center = workspace.Sun
local planet = script.Parent

local ORBIT_TIME = 10
local RADIUS = 30
local ECLIPSE = 0.8 --50% as small radius on the short side, if 1 it's a perfect circle
local ROTATION = CFrame.Angles(0,0,0) --Rotate which direction to rotate around

local sin, cos = math.sin, math.cos
local ROTSPEED = math.pi*2/ORBIT_TIME

local runservice = game:GetService('RunService')
local rot = 0
game:GetService('RunService').Stepped:connect(function(t, dt)
	rot = rot + dt * ROTSPEED
	local answer = ROTATION **ECLIPSE, 0, cos(rot)*RADIUS) 
		+ center.Position
	planet.CFrame = answer * CFrame.fromEulerAnglesXYZ(0,0.1,0)
        -- * CFrame.fromEulerAnglesXYZ(0,0.1,0): this code makes it spin

I tried checking if it actually spins without orbiting and it works, setting different speeds still doesn’t work, this is probably because it’s overridden but I don’t know how to fix it.

You’re using a fixed “spin” value (0.1 radians on Y axis), multiplied against the orbit CFrame. The orbit CFrame is always constructed from a non-rotated origin, thus you get the fixed & non-spinning planet in orbit.

To fix this, you need to do the same thing you did for rot but add another variable for spin. Then plug that in instead of your 0.1 value.