-- Variables
local Enumeration = Enum
local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local UserInputService = Game:GetService("UserInputService")
-- Camera
local Camera = Workspace.CurrentCamera
local defaultCameraPosition = Camera.CFrame.p
--Character
local player = game.Players.LocalPlayer
local char = player.Character or player.CahracterAdded:Wait()
local head = char:WaitForChild("Head")
local Humanoid = char:WaitForChild("Humanoid")
local Connection
local function OnRenderStep(Input)
Camera.CFrame = Camera.CFrame * CFrame.Angles(0, 0, if Input == "Q" then math.pi / 20 elseif Input == "E" then -math.pi / 20 else 0)
--WAIT FUNCTION HERE
Humanoid.CameraOffset = Vector3.new(if Input == "Q" then math.pi/ -2 elseif Input == "E" then math.pi/ 2 else 0,0,0)
end
local function OnInputBegan(InputObject, GameProcessed)
if GameProcessed then return end
local Input = InputObject.KeyCode.Name
if not (Input == "Q" or Input == "E") then return end
if Connection and Connection.Connected then return end
Connection = RunService.RenderStepped:Connect(function() OnRenderStep(Input) end)
end
local ray = Ray.new(head.Position, ((head.CFrame + head.CFrame.LookVector * 2) - head.Position).Position.Unit)
local ignoreList = char:GetChildren()
local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
local function OnInputEnded(InputObject, GameProcessed)
if GameProcessed then return end
local Input = InputObject.KeyCode.Name
if not (Input == "Q" or Input == "E") then return end
if Connection then Connection:Disconnect() end
Humanoid.CameraOffset = Vector3.new(0, 0, -1)
end
UserInputService.InputBegan:Connect(OnInputBegan)
UserInputService.InputEnded:Connect(OnInputEnded)
This a peek script am working on, (most of this is created by someone in this devforum. I just added the moving it left to right) wont work without adding wait() function.
If I do add the wait function it’s a little glitchy. Does anyone know how to fix this? It works on my game with more scripts and models but not a newer game with nothing but this, This might give you guys a clue on how to solve this. Thanks!