Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
soutpansa 120
5 years ago

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

0
Position is a Vector3 value, not a CFrame value. User#19524 175 — 5y
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. soutpansa 120 — 5y
0
You can't multiply a Vector3, you can only add. User#19524 175 — 5y
0
I'm pretty sure that you can multiply a Vector3. soutpansa 120 — 5y
View all comments (4 more)
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. dpark19285 375 — 5y
0
So, any ideas on how I should fix this? Changing it all to CFrame still glitches it out pretty bad soutpansa 120 — 5y
0
Is the script a local script? awesomeipod 607 — 5y
0
When you test in studio, everything is local. In a normal game, server scripts can lag or delay. awesomeipod 607 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

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 soutpansa 120 — 5y
0
I've edited the code. Looks like I wrote satellite instead of body on line 3. dpark19285 375 — 5y
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 soutpansa 120 — 5y
0
Changing it to Heartbeat just makes it bug out again :l soutpansa 120 — 5y
0
Should've specified that I was trying to do it server sided, sorry soutpansa 120 — 5y
Ad

Answer this question