Changing Orientation by every frame brokes character

Hi there.

I don’t have a bunch information to give, title says it all. I’ll try to attach a video soon for the sake of better understanding. Here is my code:

local RunService = game:GetService("RunService")

local Player = game:GetService("Players").LocalPlayer
local HRP = Player.Character.HumanoidRootPart

RunService.RenderStepped:Connect(function() if HRP.Orientation ~= 90 then HRP.Orientation = Vector3.new(0, 90, 0) end end)

Thanks in advance he

The orientation is never equal to 90, since a Vector3 is never 90. Try changing your code to math.round(HRP.Orientation.Y).

1 Like

You do have a point there. The thing is, the character brokes even without the ‘if’ conditional.

You should be using CFrame instead and you should change your code to this:

local RunService = game:GetService("RunService")

local Player = game:GetService("Players").LocalPlayer
local HRP = Player.Character.HumanoidRootPart

RunService.RenderStepped:Connect(function()
	HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(0, math.pi/2, 0)
end)

Wait, but why does this work while using .Orientation does not?

I’m not sure, it probably has to do with the “Root” Motor6D located in the LowerTorso of R15 rigs or the “Root Hip” of R6 rigs. Motor6D has gotten updated so that changing the orientation will move the joint and we don’t want that. The behavior of CFrame has not changed so it should work.

1 Like

Hi there @SubtotalAnt8185!

See, solution worked but I don’t know how to do apply it to another functionality I’ve got. Here is the script. It throws this one error, by reference:


local RunService = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local RE = RS["Remote Events"].Game.AvatarChanged
local HRP = Player.Character.HumanoidRootPart

function SetAngles(Boolean)
        for I = 1, 90 do 
                if Boolean then HRP.CFrame += CFrame.new(Vector3.new(0, 0, 0)) * CFrame.Angles(0, math.rad(I), 0)
                else HRP.CFrame -= CFrame.new(Vector3.new(0, 0, 0)) * CFrame.Angles(0, math.rad(I), 0) end

                task.wait(0.011)
        end
end

RE.OnClientEvent:Connect(function() HRP = Player.Character.HumanoidRootPart end)

RunService.Stepped:Connect(function()
        UIS.InputBegan:Connect(function(Input, GameProcessed)
                if not GameProcessed then
                        if Input.UserInputType == Enum.UserInputType.Keyboard then
                                if Input.KeyCode == Enum.KeyCode.Q then SetAngles(true)                                        
                                elseif Input.KeyCode == Enum.KeyCode.E then SetAngles(false)
                                end
                        end
                end
        end)
end)

This is your issue. You can only subtract a Vector3 from a CFrame, you might as well remove the subtraction line. The same goes for adding.

Edit: In addition, you need to add your position to the orientation, and you should be using RunService.RenderStepped:Wait() instead of task.wait for this task. Also, you should not be adding the orientation or subtracting it, you should make the number negative if boolean is true. Then, it should work.

1 Like

Okay, so this should work:

local RunService = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local RE = RS["Remote Events"].Game.AvatarChanged
local HRP = Player.Character.HumanoidRootPart

local Rad = HRP.Orientation.Y
local Rotating = false
local LookV = 0

function SetLookV(Boolean)
        if Boolean then
                if LookV == 0 then LookV = 6
                elseif LookV == 2 then LookV = 0
                elseif LookV == 4 then LookV = 2
                elseif LookV == 6 then LookV = 4
                end
        else
                if LookV == 0 then LookV = 2
                elseif LookV == 2 then LookV = 4
                elseif LookV == 4 then LookV = 6
                elseif LookV == 6 then LookV = 0
                end
        end
end

function SetAngles(Boolean)
        if not Rotating then
                for I = 1, 90 do
                        Rotating = true

                        if ((I / 10) % 1) == 0 then task.wait() end

                        if Boolean then HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(0, math.rad(Rad + I), 0)
                        else HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(0, math.rad(Rad - I), 0) end

                        Rotating = false
                end
                
                SetLookV(Boolean)
        end
end

RE.OnClientEvent:Connect(function() HRP = Player.Character.HumanoidRootPart end)

UIS.InputBegan:Connect(function(Input, GameProcessed)
        if not GameProcessed then
                if Input.UserInputType == Enum.UserInputType.Keyboard then
                        if Input.KeyCode == Enum.KeyCode.Q then SetAngles(true)                                        
                        elseif Input.KeyCode == Enum.KeyCode.E then SetAngles(false)
                        end
                end
        end
end)

RunService.Stepped:Connect(function()
        if not Rotating then
                Rad = HRP.Orientation.Y

                if LookV == 0 then HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(0, math.rad(90), 0)  
                elseif LookV == 2 then HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(0, math.rad(0), 0)  
                elseif LookV == 4 then HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(0, math.rad(-90), 0)  
                elseif LookV == 6 then HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(0, math.rad(180), 0)  
                end
        end
end)

Tysm c:
My last post is about feedback for the game I used this for, if you wanna check out.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.