Hey there, I am trying to make a custom character and I have made the script but whenever I play the game the camera on the client is REALLY weird and starts freaking out. I was trying to make a gun game and add real animations by the way but the player just wouldn’t turn. Here is the script:
wait(2)
local Player = game.Players.LocalPlayer
local Mouse = game.Players.LocalPlayer:GetMouse()
script.TurnPlayer.Mouse.Value = Mouse
local MouseX = 0
local MouseY = 0
local CamPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
game:GetService("RunService").Stepped:Connect(function()
game.Workspace.Camera.CameraType = Enum.CameraType.Scriptable
game.Workspace.Camera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame or game.Players.LocalPlayer.Character:WaitForChild("Head").CFrame
game.Players.LocalPlayer.Character.Body.Transparency = 1
game.Workspace.Camera.CameraType = Enum.CameraType.Scriptable
MouseX = Mouse.X * script.Index.Value
MouseY = Mouse.Y * script.Index.Value
script.MouseX.Value = MouseX
script.MouseY.Value = MouseY
game.Players.LocalPlayer.Character.HumanoidRootPart.Orientation = Vector3.new(0,MouseX,0)
end)
local Player = game.Players.LocalPlayer
local Mouse = game.Players.LocalPlayer:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local Head = Character:WaitForChild("Head")
local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
local camHeight = 4
script.TurnPlayer.Mouse.Value = Mouse
local MouseX = 0
local MouseY = 0
game:GetService("RunService").Stepped:Connect(function()
Camera.CFrame = (Root.CFrame + Root.CFrame.UpVector) * camHeight
MouseX = Mouse.X * script.Index.Value
MouseY = Mouse.Y * script.Index.Value
script.MouseX.Value = MouseX
script.MouseY.Value = MouseY
Root.CFrame = Root.CFrame * CFrame.Angles(MouseY, 0, 0) * CFrame.Angles(0, MouseX, 0)
end)
there is a few other issues to worry about. (like not waiting for your assets properly and indexing too much)
another thing is that you dont want to place your camera relative to your head position. (the head moves with certain animations and it can be terrible.) HOWEVER, the HumanoidRootPart doesn’t move at all with animations, so use that instead and then add a offset on the Y axis (camera height) to target the heads location.
CFrame is better to use for this sort of thing. (And you can use math.rad() to target proper radians, and get a full circle rather than unpredicted angles)
I also used .Angles twice to prevent tilting
You may also want to learn how math.clamp(n, min, max) works so you can set min/max angles for your turns. (if needed)