local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()
local Humanoid = character:WaitForChild("Humanoid")
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
local Torso = character.Torso
local RootJoint = HumanoidRootPart.RootJoint
local LeftHipJoint = Torso["Left Hip"]
local RightHipJoint = Torso["Right Hip"]
local LeftHipJointC0 = LeftHipJoint.C0
local RightHipJointC0 = RightHipJoint.C0
local Neck = Torso:WaitForChild("Neck")
local Waist = HumanoidRootPart:WaitForChild("RootJoint")
local NeckOriginC0 = Neck.C0
local WaistOriginC0 = Waist.C0
Neck.MaxVelocity = 1/3
local connection
local HeadController = {}
function rotateHead(Character)
local CameraCFrame = Camera.CoordinateFrame
if Character:FindFirstChild("Torso") and Character:FindFirstChild("Head") then
print("character and head")
local TorsoLookVector = Torso.CFrame.lookVector
local HeadPosition = Character.Head.CFrame.p
if Neck and Waist then
print("neck and waist")
if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then
local Point = Mouse.Hit.p
print("camera has character")
local Distance = (Character.Head.CFrame.p - Point).magnitude
local Difference = Character.Head.CFrame.Y - Point.Y
local goalNeckCFrame = CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 1, 0)
Neck.C0 = Neck.C0:lerp(goalNeckCFrame * NeckOriginC0, 0.5 / 2).Rotation + NeckOriginC0.Position
local xAxisWaistRotation = -(math.atan(Difference / Distance) * 0.5)
local yAxisWaistRotation = (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 0.5
local rotationWaistCFrame = CFrame.Angles(xAxisWaistRotation, yAxisWaistRotation, 0)
local goalWaistCFrame = rotationWaistCFrame*WaistOriginC0
Waist.C0 = Waist.C0:lerp(goalWaistCFrame, 0.5 / 2).Rotation + WaistOriginC0.Position
local currentLegCounterCFrame = Waist.C0*WaistOriginC0:Inverse()
local legsCounterCFrame = currentLegCounterCFrame:Inverse()
RightHipJoint.C0 = legsCounterCFrame * RightHipJointC0
LeftHipJoint.C0 = legsCounterCFrame * LeftHipJointC0
print("bottom of function everything works")
end
end
end
end
connection = RunService.RenderStepped:Connect(function()
if Player.Character and Player.Character.HumanoidRootPart then
rotateHead(character)
end
end)
Player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
if connection then
connection:Disconnect()
end
connection = RunService.RenderStepped:Connect(function()
if Player.Character and Player.Character.HumanoidRootPart then
rotateHead(character)
end
end)
end)
return HeadController
my function works perfectly fine up until the character is respawned. everything still prints but the logic in my function doesnt work. i copy and pasted the whole script into a local script and it worked perfectly fine but it wont work in a module script. im requiring it from this script below
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Controllers = ReplicatedStorage:WaitForChild("Controllers")
local player = game.Players.LocalPlayer
repeat task.wait(.1) until player.Character or player.CharacterAdded
local ControllerBlacklist = {
}
function LoadControllers(controllers)
for _, controller in controllers:GetChildren() do
if controller:IsA("ModuleScript") and not table.find(ControllerBlacklist, controller.Name) then
local success, error = pcall(function()
require(controller)
end)
if error then
warn(error)
end
end
end
end
LoadControllers(Controllers)
output shows no errors but everything in my function still prints and everything else seems to be working just fine except the logic doesnt go through