I have no clue what key:byte() does, also I am unfamiliar with Mouse functions as I use the UserInputService, but how I would go about setting this up is doing the following:
local LockOn = Instance.new("BoolValue")
Mouse.KeyDown:Connect(function(key)
if WhateverYouWant == true then
LockOn.Value = true
else
LockOn.Value = false
end
end)
local MyFunc
LockOn.Changed:Connect(function()
if LockOn.Value then
MyFunc = RS.Stepped:Connect(function()
--All of your lerping stuff
end)
else
MyFunc:Disconnect()
end
end)
In order to do this same thing with UserInputService, you do this:
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input, GHE)
--there is also an InputEnded if you want to detect when you stop pressing a key
--GHE stands for 'Game Handled Event', this will be true if you press keys during something like typing in chat, where you aren't necessarily doing something ingame
if GHE then
return
--ignore if it's handled by the game
end
if Input.KeyCode == Enum.KeyCode.LeftControl then
--do stuff
end
end)
It’s not harder, just weird looking at first. I know enough to tell you that in general, UIS is better. I don’t know enough to really tell you why, sadly.
Oh alright, Have you perhaps got discord where you could go more into detail about userinput? Or do you not/do not want to give it, Since the responding time on here of me takes a while.
Oh alright then, Kinda sucks my camera is still stuttering, If you wanna know what i mean then join this game, Put your cursor over a NPC and press CTRL.
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local Target
local Locked = false
local LockOn = RS.Stepped:Connect(function()
if Locked == true then
wait()
local LookDirection = CFrame.new(Camera.CFrame.Position, Target.Position)
local NewCFrame = CFrame.new(Camera.CFrame.Position) * LookDirection
Camera.CFrame = Camera.CFrame:lerp(NewCFrame, 0.15)
end
end)
UIS.InputBegan:Connect(function(Input, GHE)
if GHE then
return
end
if Input.KeyCode == Enum.KeyCode.LeftControl then
if Locked == false then
if Mouse.Target.Parent:FindFirstChild("HumanoidRootPart") then
Locked = true
Target = Mouse.Target.Parent.HumanoidRootPart
end
elseif Locked == true then
Locked = false
end
end
end)
I’ve written the code as I suggested above, and haven’t run into any stuttering issues. Here’s what I have.
local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Camera = game.Workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()
local Target
local LookFunc
UIS.InputBegan:Connect(function(Input, GHE)
if GHE then
return
end
if Input.KeyCode == Enum.KeyCode.LeftControl then
if Target then
LookFunc:Disconnect()
Target = nil
else
Target = Mouse.Target:FindFirstAncestorOfClass("Model") and Mouse.Target:FindFirstAncestorOfClass("Model"):FindFirstChild("HumanoidRootPart", true)
if Target then
LookFunc = RS.Stepped:Connect(function()
local LookDirection = CFrame.new(Camera.CFrame.Position, Target.Position)
local NewCFrame = CFrame.new(Camera.CFrame.Position) * LookDirection
Camera.CFrame = Camera.CFrame:lerp(NewCFrame, 0.15)
end)
end
end
end
end)
There were a couple things I changed, but one thing that stood out to me was the wait() in your RS.Stepped function. The function already runs on each frame, but you’re telling the script to yield for however long a wait() is (i think 0.05 seconds). I think that would give you 0.05 seconds of free camera movement before it tweens that frame, but that doesn’t explain why it was yanking the camera back to some other position.
Oh yeah i forgot it does each frame so wait() wasnt even needed, Anyways it works so i guess ill take your code and see what might have caused the stuttering.
Thank you so much for helping, This really made me learn way more about cameras!