Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local setting = {
- KeyToActive = Enum.KeyCode.K,
- TurnDeg = 15,
- KeyToTurnOff = Enum.KeyCode.P,
- range = 30
- }
- local player = game.Players.LocalPlayer
- local character = player.Character
- local localroot = character:WaitForChild("HumanoidRootPart")
- local UIS = game:GetService("UserInputService")
- local function closest()
- local target = nil
- for i, v in pairs(game.Players:GetPlayers()) do
- if v ~= player and v.Character then
- local KJ = v.Character:FindFirstChild("HumanoidRootPart")
- if KJ then
- local dist = (localroot.Position - KJ.Position).magnitude
- if dist < setting.range then
- target = v.Character
- end
- end
- end
- end
- return target
- end
- local newtarget = closest()
- game:GetService("RunService").RenderStepped:Connect(function()
- newtarget = closest()
- end)
- local active = false
- local function ActiveScript()
- if active == true and newtarget then
- local JN = newtarget:FindFirstChild("HumanoidRootPart")
- local JNR = newtarget:FindFirstChildOfClass("Humanoid")
- local distTwo = (localroot.Position - JN.Position).magnitude
- if JN and JNR and JNR.Health > 0 then
- while active and distTwo < setting.range and JNR.Health > 0 do
- game:GetService("RunService").RenderStepped:Wait()
- if distTwo < setting.range then
- localroot.CFrame = CFrame.lookAt(localroot.Position, JN.Position) * CFrame.Angles(0, math.rad(setting.TurnDeg), 0)
- distTwo = (localroot.Position - JN.Position).magnitude
- end
- end
- end
- end
- end
- UIS.InputBegan:Connect(function(input)
- if input.KeyCode == setting.KeyToActive then
- active = true
- elseif input.KeyCode == setting.KeyToTurnOff then
- active = false
- end
- end)
- game:GetService("RunService").RenderStepped:Connect(function()
- ActiveScript()
- end)
- game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
- wait(1)
- character = char
- localroot = character:WaitForChild("HumanoidRootPart")
- wait(0.1)
- ActiveScript()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement