Rotating part Not sure how to do it

  1. What do you want to achieve? Rotating part like in obbies

  2. What is the issue? Not sure how to do it

2 Likes

Use a Tween, perhaps? You could do something along the lines of:

local RotationTween = TweenService:Create(RotatingPart, 
    TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1), 
    {RotatingPart.CFrame = RotatingPart.CFrame * CFrame.Angles(0, math.rad(360), 0)})

RotationTween:Play()
2 Likes

Ill try btw great response times here on the forums.

3 Likes

Use CFrame.
Here is a basic one:

local r = 1 -- speed per second
local RunService = game:GetService("RunService")
local part = script.Parent

while true do
   local dt= RunService.Heartbeat:Wait() -- Smooths rotation
   part.CFrame = part.CFrame * CFrame.fromEulerAnglesXYZ(r*dt,r*dt,r*dt)
end

This is not as simplistic as a regular spin script, but looks a lot smoother.

  • RunService is the service that gets stuff like framerate
  • Heartbeat is the forced 60FPS value, calculated by how healthy the server is
  • CFrame.fromEulerAnglesXYZ() is a part of CFrame that determines a rotation in radians (NOT DEGREES).
1 Like

It does spin but a bit wierd It spins like a bit vertical and a bit horizontal

Ok, we can edit the code.

local rX,rY,rZ = 0,1,0 -- Change the numbers for speed on each axis
local RunService = game:GetService("RunService")
local part = script.Parent

while true do
   local dt= RunService.Heartbeat:Wait() -- Smooths rotation
   part.CFrame = part.CFrame * CFrame.fromEulerAnglesXYZ(rX*dt,rY*dt,rZ*dt)
end
2 Likes

Works well thanks iGottic! Im gonna say it was a solution!

Oh wait any way you can move the player with this

If you want to move the player, you should look into BodyAngularVelocity, as I think that would move the player as well.

I want to move a player with a moving part if they are touching it

That’s a whole different story, as it requires using physics.
I warn you doing this is MUCH less optimized and will lag your game when used a lot.

Here is a basic script, but it doesn’t work too well:

local rotate = Instance.new("BodyAngularVelocity",script.Parent)
rotate.AngularVelocity = Vector3.new(0,5,0) -- Change numbers as needed, follows XYZ format.
rotate.P = 1250 -- Rotate power

local forcedPos = Instance.new("BodyPosition",script.Parent)
forcedPos.Position = script.Parent.Position
forcedPos.D = 0
forcedPos.P = 1000000
forcedPos.MaxForce = Vector3.new(1,1,1) * forcedPos.P

script.Parent.Anchored = false

Any simple way you can optimize it

The game has to be really optimized because there is gonna be about 100 towers total like 12 spinny things per tower

Yes, here is a simple optimised version:

local rotate = Instance.new("BodyAngularVelocity")
rotate.AngularVelocity = Vector3.new(0,5,0)
rotate.P = 1250 -- Rotate power
rotate.Parent = script.Parent

local forcedPos = Instance.new("BodyPosition")
forcedPos.Position = script.Parent.Position
forcedPos.D = 0
forcedPos.P = 1000000
forcedPos.MaxForce = Vector3.new(1,1,1) * forcedPos.P
forcedPos.Parent = script.Parent

script.Parent.Anchored = false

That’s not optimized. That’s actually less optimized.

How is it less optimised? By setting the parent manually on a seperate line, it is faster.

Yea, I would stick with the initial method. Too many active unachored parts will destroy your game.

No. The Instance constructor function has the parent as an optional passed argument. Creating another line of code for that makes Lua take more time to process what you said.

Besides, the code is more-so unoptimized because the part is unanchored.

If i t was unanchored it would not even work for me
im planning on making some you have to jump on and than wait until it moves you onto the next jump

Please take a read of this post here: PSA: Don't use Instance.new() with parent argument