Hi! My problem is that I can't get the random number generator to generate decimals. I also can't get the math.random function to work at all.

What I thought was right and apparently wasn't right, and this is what I did: (Lines 17-24 are not related to the question)

local origin = workspace.Solar_System.Sun --The center part we're orbiting
local orbit = script.Parent --The part that will be moving
local distanceFromSun = 30 --default for first planet
local i = 0 --Increment
local decimal = nil
local orbitSpeed = script.OrbitSpeed
local function generateOrbitSpeed()
	decimal = math.random(1,2) --picks if the speed should be a decimal or not (1 = no decimal, 2 = decimal)
	if decimal == 2 then
		orbitSpeed = math.random(10, 50)
		orbitSpeed = orbitSpeed % 1 --Turns it into a decimal
	else
		orbitSpeed = math.random(1, 2)
	end
end

while true do
    --Start at origin then apply an offset using Angles()
    orbit.CFrame = CFrame.new(origin.Position) * CFrame.Angles(0, i, 0) * CFrame.new(0, 0, distanceFromSun)
		script.Parent.OrbitTrailKeeper.CFrame = CFrame.new(origin.Position) * CFrame.Angles(0, i, 0) * CFrame.new(0, 0, 60)
    --Increment i by 5 degrees every wait()
    i = i + math.rad(orbitSpeed.Value)
    wait()
end

So, yeah. That's my problem. If you can fix it or have anything that can help me (not the Roblox wiki link please, anything other then that) I would very much appreciate that. Thanks! :)

3 comments

2

Why are you using modulus? Have you tried printing the result of orbitspeed % 1? I attempted it, and always got 0. Would it not give you a decimal to instead divide by 100 instead of % 1?

1

or add + math.random() so it's a decimal.

0

That worked thank you! :D