I want to make a lock on system similar to
Hey! I saw your comment and understood you’re looking for a Lock-On system. These systems aren’t too hard to create, and I actually made one myself while working on some combat systems for my own games.
I can share the script I made with you. It’s written in a LocalScript, and you can adjust it to fit your own needs. Here’s how to get started:
- Go to
StarterPlayer>StarterPlayerScripts. - Create a LocalScript.
- Paste this code inside:
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local locked = false
local target = nil
local function getTarget()
local ray = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 1000, RaycastParams.new())
if ray and ray.Instance then
local model = ray.Instance:FindFirstAncestorOfClass("Model")
if model and model:FindFirstChild("Humanoid") and model ~= player.Character then
return model
end
end
return nil
end
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.L then
if not locked then
local result = getTarget()
if result then
target = result
locked = true
end
else
locked = false
target = nil
end
end
end)
runService.RenderStepped:Connect(function()
if locked and target and target:FindFirstChild("HumanoidRootPart") then
local hrp = target.HumanoidRootPart
local cam = workspace.CurrentCamera
cam.CFrame = CFrame.new(cam.CFrame.Position, hrp.Position)
end
end)
Now just test it with an NPC or any model that has a Humanoid. Press L to lock/unlock the camera onto the target.
This is a simple prototype I made to test how the camera behaves when locked onto something. Feel free to modify or expand it with smooth transitions, UI indicators, or multi-target selection — whatever your game needs!
Hope this helps! ![]()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.