I literally have no idea what’s wrong, no errors, I have it as a modulescript, got it in serverscriptservices etc, any ideas?
local Players = game:GetService("Players")
local Target = nil
local function pickTarget()
local Mouse = Players.LocalPlayer:GetMouse()
local Character = Players.LocalPlaye.Character
if not (Mouse and Character) then return end
local MaxDistance = 50 --change this to adjust targeting range
local Origin = Character.HumanoidRootPart.Position
local Direction = (Mouse.Hit.Position - Origin).Unit
local part, hitpos = workspace:FindPartOnRayWithWhitelist(Ray.new(Origin, Direction * MaxDistance),{Character})
while part and part.CanCollide == false do
part, hitpos = workspace:FindPartOnRayWithIgnoreList(Ray.new(hitpos, Direction * MaxDistance), {Character})
end
Target = (part and part.Parent and part.Parent:FindFirstChild("Humanoid") and part.Parent.Humanoid or nil)
end
local function getRotation(part)
if not part then return nil end
if not part:IsA("BasePart") then return nil end
local camCFrame = workspace.CurrentCamera.CFrame
local look = (camCFrame.p - part.Position).Unit
local up = part.CFrame.UpVector
local right = up:Cross(look).unit
local newUp = look:Cross(right)
return CFrame.fromMatrix(part.Position, right, newUp)
end
local function updateTargeting()
local Character = Players.LocalPlayer.Character
if not (Character and Target) then return end
local TargetPart = Target.Parent.PrimaryPart
if not TargetPart then TargetPart = Target.Parent:FindFirstChildWhichIsA("BasePart") end
if not TargetPart then return end
local CurrentRotation = getRotation(Character.HumanoidRootPart)
local TargetRotation = getRotation(TargetPart)
if not (CurrentRotation and TargetRotation) then return end
local AngleBetween = math.acos(CurrentRotation.LookVector:Dot(TargetRotation.LookVector))
if AngleBetween > math.rad(20) then return end -- change this to adjust lock onm angle
Character.Humanoid.AutoRotate = false
Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.Position, TargetPart.Position)
end
game:GetService("RunService").RenderStepped:Connect(function()
pickTarget()
updateTargeting()
end)
Ok so I scrapped the other one and went for another one, but now this one is getting an error on line 49 saying that it’s attempting to suffix nil for the humanoid, not sure what’s going on with this one lmbo.
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local InputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local target = nil
local targetModel = Instance.new("Model", workspace)
targetModel.Name = "Target Model"
local targetPart = Instance.new("Part")
targetPart.Size = Vector3.new(2,2,2)
targetPart.Transparency = 0.7
targetPart.BrickColor = BrickColor.new("Institutional white")
targetPart.CanCollide = false
targetPart.Anchored = true
targetPart.Parent = targetModel
local function findTarget()
local nearestDistance = math.huge
for _,player in pairs(Players:GetPlayers())do
if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health>0 then
local distance = (player.Character.HumanoidRootPart.Position - LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if distance < nearestDistance then
nearestDistance = distance
target = player.Character.HumanoidRootPart
end
end
end
end
local function onInput(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
if input.UserInputState == Enum.UserInputState.Begin then --Player has pressed shift
findTarget()
elseif input.UserInputState == Enum.UserInputState.End then --Player has stopped pressing shift
target = nil
end
end
end
InputService.InputChanged:Connect(onInput)
while true do
if target then
local targetPosition = target.Position + Vector3.new(0, targetPart.SizeY/2,0)
targetPart.CFrame = CFrame.new(targetPosition)
Camera.CameraSubject = target
Camera.CameraType = Enum.CameraType.Attach
else
Camera.CameraSubject = LocalPlayer.Character.Humanoid
Camera.CameraType = Enum.CameraType.Custom
end
wait(0.1)
end
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local InputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local target = nil
local targetModel = Instance.new("Model", workspace)
targetModel.Name = "Target Model"
local targetPart = Instance.new("Part")
targetPart.Size = Vector3.new(2,2,2)
targetPart.Transparency = 0.7
targetPart.BrickColor = BrickColor.new("Institutional white")
targetPart.CanCollide = false
targetPart.Anchored = true
targetPart.Parent = targetModel
local function findTarget()
local nearestDistance = math.huge
for _,player in pairs(Players:GetPlayers())do
if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health>0 then
local distance = (player.Character.HumanoidRootPart.Position - LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if distance < nearestDistance then
nearestDistance = distance
target = player.Character.HumanoidRootPart
end
end
end
end
local function onInput(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
if input.UserInputState == Enum.UserInputState.Begin then --Player has pressed shift
findTarget()
elseif input.UserInputState == Enum.UserInputState.End then --Player has stopped pressing shift
target = nil
end
end
end
InputService.InputChanged:Connect(onInput)
while true do
if target then
local targetPosition = target.Position + Vector3.new(0, targetPart.SizeY/2,0)
targetPart.CFrame = CFrame.new(targetPosition)
Camera.CameraSubject = target
Camera.CameraType = Enum.CameraType.Attach
else
Camera.CameraSubject = LocalPlayer.Character:WaitForChild(“Humanoid”)
Camera.CameraType = Enum.CameraType.Custom
end
wait(0.1)
end