I tried to make a simple third person aim script where the character faces where camera points, but after the character dies the script doesn't work anymore. How can I fix it? Any other way of creating an aim script? Any help is appreciated.
AIM SCRIPT I TRIED
local userInputService = game:GetService("UserInputService") local UserGameSettings = UserSettings():GetService("UserGameSettings") userInputService.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then UserGameSettings.RotationType = Enum.RotationType.CameraRelative end end) userInputService.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then UserGameSettings.RotationType = Enum.RotationType.MovementRelative end end) userInputService.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton2 then UserGameSettings.RotationType = Enum.RotationType.CameraRelative end end) userInputService.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton2 then UserGameSettings.RotationType = Enum.RotationType.MovementRelative end end)
CAMERA SCRIPT
------------- --- INDEX --- ------------- --Services local userInputService = game:GetService("UserInputService") local runService = game:GetService("RunService") local UserGameSettings = UserSettings():GetService("UserGameSettings") --Player & Character local localPlayer = game:GetService("Players").LocalPlayer --Other local Camera = game:GetService("Workspace").CurrentCamera Camera.FieldOfView = 80 -------------- --- VALUES --- -------------- local clothing = game.StarterGui.Clothing local xAngle = 0 local yAngle = 0 local cameraPos = Vector3.new(3,0,7.5) ---------------------- --- INITIALIZATION --- ---------------------- userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter wait(1) Camera.CameraType = Enum.CameraType.Scriptable userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter ----------------- --- FUNCTIONS --- ----------------- userInputService.InputChanged:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseMovement then xAngle = xAngle-input.Delta.x*0.4 --Clamp the vertical axis so it doesn't go upside down or glitch. yAngle = math.clamp(yAngle-input.Delta.y*0.4,-80,80) end end) runService.RenderStepped:Connect(function() local Character = localPlayer.Character local rootPart = Character:FindFirstChild("HumanoidRootPart") if Character and rootPart then --Set rotated start cframe inside head local startCFrame = CFrame.new((rootPart.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0) --Set camera focus and cframe local cameraCFrame = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,cameraPos.Z)) local cameraFocus = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,-50000)) Camera.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p) end end)