Hello people from Forum. I want help on a script. The script works just fine. It’s a script where it moves your torso, following your camera’s movement. The problem is that when you look too high with your camera it ‘glitches’, but only when theres some part or something. But when I’m looking at the sky, nothing happens, it works just fine. I think It’s just a small mistake in the script that makes that happen.
By the way, it’s a Local Script located in StarterCharacterScripts.
This topic isn’t such an issue, but I would be very glad if someone solved it for me!
1. What do you want to achieve?
I want to achieve something that moves your torso in the camera’s direction, so the flashlight follows the movement too.
Here’s a video showing an example:
2. What is the issue?
The issue of this script is that the camera glitches when you’re looking up, but only when there’s a part or something. But when there’s nothing, like looking at the sky, everything’s ok and the camera doesn’t glitch.
I also don’t understand why when I record it doesn’t show the glitch that well, which makes me even more confused. I’ve tried other Forums to help me, but they couldn’t. Is it because of my GPU (computer in general), Roblox’s fault or is it the script that’s not built well?
Here’s the issue:
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried using ChatGPT since I was clueless of what was wrong. It made it worse…
Tried other Forums nothing changed.
So I’m here to see if anyone can actually help me.
And no I didn’t look for solutions on the Developer Hub since my script is unique and there’s nothing related to this topic.
Here’s the script. It’s a local script located in StarterCharacterScripts:
wait()
--[Pre-Funcs]:
local Ang = CFrame.Angles --[Storing these as variables so I dont have to type them out.]
local aSin = math.asin
local aTan = math.atan
--[Constants]:
local Cam = game.Workspace.CurrentCamera
local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Body = Plr.Character or Plr.CharacterAdded:wait()
local Head = Body:WaitForChild("Head")
local Hum = Body:WaitForChild("Humanoid")
local Core = Body:WaitForChild("HumanoidRootPart")
local IsR6 = (Hum.RigType.Value==0) --[Checking if the player is using R15 or R6.]
local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso")
local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck") --[Once we know the Rig, we know what to find.]
local Waist = (not IsR6 and Trso:WaitForChild("Waist")) --[R6 doesn't have a waist joint, unfortunately.]
--[[
[Whether rotation follows the camera or the mouse.]
[Useful with tools if true, but camera tracking runs smoother.]
--]]
local MseGuide = true
--[[
[Whether the whole character turns to face the mouse.]
[If set to true, MseGuide will be set to true and both HeadHorFactor and BodyHorFactor will be set to 0]
--]]
local TurnCharacterToMouse = true
--[[
[Horizontal and Vertical limits for head and body tracking.]
[Setting to 0 negates tracking, setting to 1 is normal tracking, and setting to anything higher than 1 goes past real life head/body rotation capabilities.]
--]]
local HeadHorFactor = 1
local HeadVertFactor = 1
local BodyHorFactor = 1.5
local BodyVertFactor = 1.4
--[[
[How fast the body rotates.]
[Setting to 0 negates tracking, and setting to 1 is instant rotation. 0.5 is a nice in-between that works with MseGuide on or off.]
[Setting this any higher than 1 causes weird glitchy shaking occasionally.]
--]]
local UpdateSpeed = 0.5
local NeckOrgnC0 = Neck.C0 --[Get the base C0 to manipulate off of.]
local WaistOrgnC0 = (not IsR6 and Waist.C0) --[Get the base C0 to manipulate off of.]
--[Setup]:
Neck.MaxVelocity = 1/3
-- Activation]:
if TurnCharacterToMouse == true then
MseGuide = true
HeadHorFactor = 0
BodyHorFactor = 0
end
game:GetService("RunService").RenderStepped:Connect(function()
if game:GetService("UserInputService").MouseEnabled then
local CamCF = Cam.CoordinateFrame
if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then --[Check for the Torso and Head...]
local TrsoLV = Trso.CFrame.lookVector
local HdPos = Head.CFrame.p
if IsR6 and Neck or Neck and Waist then --[Make sure the Neck still exists.]
if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
local Dist = nil;
local Diff = nil;
if not MseGuide then --[If not tracking the Mouse then get the Camera.]
Dist = (Head.CFrame.p-CamCF.p).magnitude
Diff = Head.CFrame.Y-CamCF.Y
if not IsR6 then --[R6 and R15 Neck rotation C0s are different; R15: X axis inverted and Z is now the Y.]
Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*HeadVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang((aSin(Diff/Dist)*BodyVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
else --[R15s actually have the properly oriented Neck CFrame.]
Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor),UpdateSpeed/2)
end
else
local Point = Mouse.Hit.p
Dist = (Head.CFrame.p-Point).magnitude
Diff = Head.CFrame.Y-Point.Y
if not IsR6 then
Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aTan(Diff/Dist)*HeadVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang(-(aTan(Diff/Dist)*BodyVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
else
Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aTan(Diff/Dist)*HeadVertFactor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor), UpdateSpeed/2)
end
end
end
end
end
if TurnCharacterToMouse == true then
Hum.AutoRotate = false
Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(Mouse.Hit.p.x, Core.Position.Y, Mouse.Hit.p.z)), UpdateSpeed / 2)
else
Hum.AutoRotate = true
end
end
end)
game.ReplicatedStorage.Look.OnClientEvent:Connect(function(otherPlayer, neckCFrame, WaistCFrame)
local Neck = otherPlayer.Character:FindFirstChild("Neck", true)
local Waist = otherPlayer.Character:FindFirstChild("Waist", true)
if Neck and Waist then
game:GetService('TweenService'):Create(Neck, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = neckCFrame}):Play()
game:GetService('TweenService'):Create(Waist, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = WaistCFrame}):Play()
end
end)
while wait(0.0001) do
game.ReplicatedStorage.Look:FireServer(Neck.C0, Waist.C0)
end
Here’s the server script located in ServerScriptService, but I think that this one isn’t the problem at all, but I will still provide it since I want help…:
game.ReplicatedStorage.Look.OnServerEvent:Connect(function(player, neckCFrame, WaistCFrame, mouseenabled)
if mouseenabled then
for key, value in pairs(game.Players:GetChildren()) do
if value ~= player and (value.Character.Head.Position - player.Character.Head.Position).Magnitude < 10 then
game.ReplicatedStorage.Look:FireClient(value, player, neckCFrame, WaistCFrame)
end
end
end
end)
If you want to help me, you don’t need to write entire scripts or design entire systems for me, but rather tell me the part that’s wrong and make the changes. I don’t want to make your ‘work’ hard.