Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Orbit script makes part look laggy and move through the ground?

This script is supposed to make a part orbit around the player. It test mode, it works perfectly and orbits around the player in a complete circle, smooth and everything. In the normal game, it just glitches around them then decides, "oh hey I'll go through the ground now". (Gotta love roblox's perfect and reliable test mode)

Here is the script, any idea what's causing this?

local Satellite = script.Parent
local Body = script.Parent.Parent.HumanoidRootPart


orbitPeriod = 2
orbitRadius = 10
orbitVerticalDisplacement = 0
for t = 0, math.huge do
	Satellite.Position = CFrame.new(Body.Position)*CFrame.Angles(0, t/orbitPeriod * math.pi/30, 0)*Vector3.new(orbitRadius, orbitVerticalDisplacement, 0)
	game['Run Service'].Heartbeat:wait()
end

Thanks for reading

8 comments

0

Position is a Vector3 value, not a CFrame value.

0

Changing it from CFrame to Vector3 gives me this error: attempt to multiply a Vector3 with an incompatible value type or nil, and it doesn't work at all.

0

You can't multiply a Vector3, you can only add.

0

I'm pretty sure that you can multiply a Vector3.

0

It is possible to multiply a Vector3 to an int or float value, but not with a CFrame, such as what you are trying to do.

0

So, any ideas on how I should fix this? Changing it all to CFrame still glitches it out pretty bad

0

Is the script a local script?

0

When you test in studio, everything is local. In a normal game, server scripts can lag or delay.

1 answer

I'm pretty sure something such as this works:

local t = 0;
game:GetService("RunService").RenderStepped:Connect(function()
	satellite.CFrame = CFrame.new(body.Position) * CFrame.Angles(0, math.rad(t), 0) * CFrame.new(0, 0, orbitRadius)
	t = t + 1;
end)

Of course, you'll have to change all of the desired variables and values, but something similar to this should work as a framework for having the "satellite" object orbit an object called "body."

Hope this helps

5 comments

0

https://gyazo.com/027d1c521c802c33cf2b8eeba0d98040 ... That's the code that I'm using, and the part just gets pushed away from the player and deleted

0

I've edited the code. Looks like I wrote satellite instead of body on line 3.

0

It seems to be working in test mode now, but I got the error "RenderStepped" event can only be used from local scripts" now

0

Changing it to Heartbeat just makes it bug out again :l

0

Should've specified that I was trying to do it server sided, sorry

This discussion is preserved as it was. New answers, comments, and votes are closed.