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

How to script an orb to rotate while it is above you?

I have been working on a script and am fairly new to scripting. I was wondering if someone could help me make the cube rotate as it is hovering above me

local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:wait()
local Model = Instance.new("Model", Character)
local Humanoid = Instance.new("Humanoid", Model)

local Cubix = Instance.new("Part", Model)
Cubix.Name = "Head"
Cubix.Shape = Enum.PartType.Block
Cubix.CanCollide = false
Cubix.BrickColor = BrickColor.new("Black")
Cubix.Transparency = 0
Cubix.Size = Vector3.new(1.5, 1.5, 1.5)
Cubix.TopSurface = Enum.SurfaceType.Smooth
Cubix.BottomSurface = Enum.SurfaceType.Smooth

Model.Name = "lpt423's Cubix"
Humanoid.MaxHealth = 0
Humanoid.Health = 0
 
local BodyPosition = Instance.new("BodyPosition", Cubix)
 
while wait(0) do
	BodyPosition.Position = Character.Head.CFrame:pointToWorldSpace(Vector3.new(3, 1, 0))
end

It's not much, but there's one key function I want and that is for the cube to rotate. Can anyone provide some insight? Thanks!

1 answer

Quick Optimization/Fix:

I'm not familiar with pointToWorldSpace, but here's what I think would work without using it:

while wait() do -- wait(0) basically waits for 0 seconds, doing nothing. wait()'s length can be set in studio settings.
	BodyPosition.Position = character.Head.Position + Vector3.new(0,1,0)
end

I don't know about this, though, so don't trust my answer on this part. If it works, it's fine.


Solution:

You may want to try using BodyGyro (makes it so the part is always facing a certain direction). If you don't understand, check out the wiki or google 'Gyro'.

local BodyGyro = Instance.new("BodyGyro",Cubix)
BodyGyro.CFrame = Cubix.CFrame -- the first parameter of CFrame is ignored in BodyGyros

while wait() do
	-- body position stuff
	BodyGryo.CFrame = BodyGyro.CFrame * CFrame.Angles(1,0,0) -- change which axis if there is problems with it rotating the wrong way (also use negatives reverse something's rotation on the same axis)
end

Hope I helped!

~TDP

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