-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNPC Lock.lua
More file actions
155 lines (139 loc) · 5.47 KB
/
Copy pathNPC Lock.lua
File metadata and controls
155 lines (139 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMode = Enum.CameraMode.Classic
local runService = game:GetService("RunService")
local StarterGui = game:GetService("StarterGui")
local camera = workspace.CurrentCamera
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "NPC_Lock_GUI"
screenGui.Parent = game:GetService("CoreGui")
local button = Instance.new("TextButton")
button.Name = "NPC Lock: ON/OFF"
button.Size = UDim2.new(0, 150, 0, 50)
button.Position = UDim2.new(0.5, -75, 0.9, -25)
button.BackgroundColor3 = Color3.new(0, 0, 0)
button.TextColor3 = Color3.new(1, 1, 1)
button.Text = "NPC Lock: OFF"
button.Font = Enum.Font.Fantasy
button.TextScaled = true
button.TextSize = 20
button.Parent = screenGui
local uicorner = Instance.new("UICorner")
uicorner.CornerRadius = UDim.new(0, 12)
uicorner.Parent = button
local dragging = false
local dragInput, dragStart, startPos
local function update(input)
local delta = input.Position - dragStart
button.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end
button.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
dragStart = input.Position
startPos = button.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
dragging = false
end
end)
end
end)
button.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
dragInput = input
end
end)
game:GetService("UserInputService").InputChanged:Connect(function(input)
if dragging and input == dragInput then
update(input)
end
end)
local npcLock = false
local lastTarget = nil
local toggleLoop
local function addPlayerHighlight()
if player.Character then
local highlight = player.Character:FindFirstChild("PlayerHighlightESP")
if not highlight then
highlight = Instance.new("Highlight")
highlight.Name = "PlayerHighlightESP"
highlight.FillColor = Color3.new(1, 1, 1)
highlight.OutlineColor = Color3.new(1, 1, 1)
highlight.FillTransparency = 0.5
highlight.OutlineTransparency = 0
highlight.Parent = player.Character
end
end
end
local function removePlayerHighlight()
if player.Character and player.Character:FindFirstChild("PlayerHighlightESP") then
player.Character.PlayerHighlightESP:Destroy()
end
end
local function getClosestNPC()
local closestNPC = nil
local closestDistance = math.huge
for _, object in ipairs(workspace:GetDescendants()) do
if object:IsA("Model") then
local humanoid = object:FindFirstChild("Humanoid") or object:FindFirstChildWhichIsA("Humanoid")
local hrp = object:FindFirstChild("HumanoidRootPart") or object.PrimaryPart
if humanoid and hrp and humanoid.Health > 0 and object.Name ~= "Horse" then
local isPlayer = false
for _, pl in ipairs(Players:GetPlayers()) do
if pl.Character == object then
isPlayer = true
break
end
end
if not isPlayer then
local distance = (hrp.Position - player.Character.HumanoidRootPart.Position).Magnitude
if distance < closestDistance then
closestDistance = distance
closestNPC = object
end
end
end
end
end
return closestNPC
end
button.MouseButton1Click:Connect(function()
npcLock = not npcLock
if npcLock then
button.Text = "NPC Lock: ON"
toggleLoop = runService.RenderStepped:Connect(function()
local npc = getClosestNPC()
if npc and npc:FindFirstChild("Humanoid") then
local npcHumanoid = npc:FindFirstChild("Humanoid")
if npcHumanoid.Health > 0 then
camera.CameraSubject = npcHumanoid
lastTarget = npc
addPlayerHighlight()
else
lastTarget = nil
removePlayerHighlight()
if player.Character and player.Character:FindFirstChild("Humanoid") then
camera.CameraSubject = player.Character:FindFirstChild("Humanoid")
end
end
else
if player.Character and player.Character:FindFirstChild("Humanoid") then
camera.CameraSubject = player.Character:FindFirstChild("Humanoid")
end
lastTarget = nil
removePlayerHighlight()
end
end)
else
button.Text = "NPC Lock: OFF"
if toggleLoop then
toggleLoop:Disconnect()
toggleLoop = nil
end
removePlayerHighlight()
if player.Character and player.Character:FindFirstChild("Humanoid") then
camera.CameraSubject = player.Character:FindFirstChild("Humanoid")
end
end
end)