How would I be able to make a LocalScript make a part orbit around the players character and for other players to be able to see it too?
I have a remote that inserts the part into the game and places it into the players character.
How would I be able to make a LocalScript make a part orbit around the players character and for other players to be able to see it too?
I have a remote that inserts the part into the game and places it into the players character.
I feel like the best way to do it is:
OrbitPart
) on the server and parent it to the character
OrbitPart
to the player server-sideOrbitPart
client-sideAfter that, you would change the OrbitPart
’s CFrame every render step:
-- in StarterCharacterScripts
local RunService = game:GetService("RunService")
local character = script.Parent
local HRP = character.HumanoidRootPart
local orbitPart = character:WaitForChild("OrbitPart")
orbitPart.Anchored = true
local CYCLE_DURATION = 3
local DISTANCE = 10
local i = 0
RunService.RenderStepped:Connect(function(dt)
i = (i + dt/CYCLE_DURATION) % 1
local alpha = 2 * math.pi * i
orbitPart.CFrame = CFrame.Angles(0, alpha, 0)
* CFrame.new(0, 0, DISTANCE)
+ HRP.Position
end)
The only issue I could see with this is an exploiter being able to manipulate the orbiting part since it’s client-owned, you can just make it CanCollide = false
server-side.
The main reason I would do it this way and not with something like welds is because I don’t want the rotation to be relative to the character’s rotation, otherwise it would look too snappy. However, if you do want the rotation to be relative, you can replace the orbitPart.CFrame = ...
part with this:
orbitPart.CFrame = HRP.CFrame
* CFrame.Angles(0, alpha, 0)
* CFrame.new(0, 0, DISTANCE)
If i wanted to make it so every time a player clicks e while a tool is equipped how would i add that to the orbit script? like so a new part starts orbitting when player clicks e during tool equip?