Need help making a space game and syncing planet position to all servers

Hi,
Im trying to make a space game but the thing is that planet positions dont sync between servers which makes things weird that servers would have the planet be at different distances
My question:How would i make it sync and is it even possible
Games that i saw that MIGHT have this:Starscape
My Ideas on the problem:
1)use datastores and read data every time the planet moves but datastores have a limit
2)use messaging service but i dont think its a reliable thing
If you have any ideas on it,Help be appreciated.Thanks.

3 Likes

You don’t have to specifically try and make it sync between servers. If all servers use the same code to move planets and it isn’t randomized it would have the same effect.

3 Likes

no i mean that if all server had the same code and the server started at different times it still would have major problems where in one server the planet will be at this position while the other would be at start position

The servers don’t all start at the same time and players are often in different time zones so the only way this would work is if you relied on os.time() to calculate their positions on a cycle.

how would i be using os.time()? can you explain it more detail?

os.time() returns the number of seconds since jan 1st, 1970 12 am. This means that this number is the same across the entire world so you could make your planets positions based around this number and it would be the same across all the server.

ok… but i dont know how i could make it… im kinda bad when it comes to time and all
but ill try something real quick

How are your planets moving currently? Is it an equation or is it physics based?

im still kinda deciding on making moving CFrames or line forces so not sure

If you use a CFrame, then interpolate the full planetary cycle on a 24 hour cycle based on os.time().

Edit: or however long you want the cycle of the planet to be

1 Like

hey there,
i made a CFrame script of orbit but i dont know how i can integrate it with os.time().Any Help?

local count = 0
local dist = 100 --How far the planet is from the star in studs
local spd = 0.001 --How fast the planet orbits.
local xangle = 0--how the planet is tilted in its orbit x axis
local yangle = 0--how the planet is tilted in its orbit y axis
local orbitparent = script.Parent.Parent.Sun
while true do 
	count += 1
	wait() 
	script.Parent.CFrame = orbitparent.CFrame*CFrame.fromEulerAnglesXYZ(xangle,count*spd,yangle)*CFrame.new(0,0,dist)
end
1 Like

count = os.time()
And please use task.wait(), lol. It’s far more reliable and consistent than wait().

Edit: or better yet, don’t use count variable; directly reference os.time() for less redundancy.

Keep in mind, your equation relies on spd to calculate the time for a full orbit. 0.001 would take 1000 seconds to complete a full orbit, which is 16.67 minutes. You can calculate minutes quite easily like so;
local spd = 1/60*10 -- a full orbit would be 10 minutes
or
local spd = 1/60*60*3 -- a full orbit would be 3 hours

Edit: My math here wasn’t quite right, see answer for correct math.

so i followed that

local count = os.time()
local dist = 100 --How far the planet is from the star in studs
local spd = 0.001 --How fast the planet orbits.
local xangle = 0--how the planet is tilted in its orbit x axis
local yangle = 0--how the planet is tilted in its orbit y axis
local orbitparent = script.Parent.Parent.Sun
while true do 
	task.wait()
	script.Parent.CFrame = orbitparent.CFrame*CFrame.fromEulerAnglesXYZ(xangle,count*spd,yangle)*CFrame.new(0,0,dist)
end

and it didnt move a single bit and i checked the position property and saw no numbers moving

That’s because you set count to os.time() outside the loop so it’s only checking os.time() once. os.time() increases by one each second.

local dist = 100 --How far the planet is from the star in studs
local spd = 0.001 --How fast the planet orbits.
local xangle = 0--how the planet is tilted in its orbit x axis
local yangle = 0--how the planet is tilted in its orbit y axis
local orbitparent = script.Parent.Parent.Sun
while task.wait() do
	script.Parent.CFrame = orbitparent.CFrame*CFrame.fromEulerAnglesXYZ(xangle,os.time()*spd,yangle)*CFrame.new(0,0,dist)
end

ye i also tried putting the local count thing in the loop and it didnt work too

script.Parent.CFrame = orbitparent.CFrame*CFrame.fromEulerAnglesXYZ(xangle,os.time()*spd,yangle)*CFrame.new(0,0,dist)

so i did this

local dist = 10 --How far the planet is from the star in studs
local spd = 1/60*10 --How fast the planet orbits.
local xangle = 0--how the planet is tilted in its orbit x axis
local yangle = 0--how the planet is tilted in its orbit y axis
local orbitparent = script.Parent.Parent.Sun
while true do
	print("working")
	wait()
	script.Parent.CFrame = orbitparent.CFrame*CFrame.fromEulerAnglesXYZ(xangle,os.time()*spd,yangle)*CFrame.new(0,0,dist)
end

and it prints but the planet doesnt move at all and i put the equation at the spd to make the planet orbit around star for 10 min and did not find a single movement after 10 min

Did it work before? When os.time() wasn’t in the code

yes when i used the count variable like the one i had at start the planets move normally