Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm making an aimbot, how do you find the nearest humanoid using magnitude?

Asked by 6 years ago

How do you find the nearest humanoid? Here's what I have, sorry if my code is trash I'm new to lua

01local m = game.Players.LocalPlayer:GetMouse()
02db = true
03m.KeyDown:connect(function(k)
04k = k:lower()
05if k == "e" then
06if db == true then
07target = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
08print("[Aimbot]: Now aimbotting: "..target.Name)
09target2 = target.Character.Torso
10local b = Instance.new("RocketPropulsion", game.Players.LocalPlayer.Character.Torso)
11b.Target = target2
12b.TurnP = 5000
13b.MaxThrust = 0
14b.MaxSpeed = 0
15b.ThrustP = 0
16b.CartoonFactor = 1
17b:Fire()
18end
19end
20end)

All I do is press "E" to switch my aim between players but it sometimes aimbots myself and glitches out also how do I find the nearest humanoid so I can change it and make it auto aim to the nearest player?

It only aimbots when you're not using lock-shift or 1st person but it's ok.

I know there's a way how to find the nearest player using magnitude but how do I do that?

https://scriptinghelpers.org/questions/54060/how-do-i-use-magnitude-to-find-the-nearest-player-in-the-game

Also I do not understand a single thing in the link above because I'm new to Lua, please help me :(

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Quick Explanation on Magnitude

Any mathematical vector has a magnitude and a direction. The magnitude is simply the size of a vector. Here's an article on vectors if you're unfamiliar with them.

Sample function

01local function GetNearestHumanoid(targetPosition)
02    local distance, humanoid = math.huge
03 
04    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
05        local character = player.Character
06        if character then
07            local characterDistance = (targetPosition - character.PrimaryPart.Position).magnitude
08            if characterDistance < distance then
09                distance = characterDistance
10                humanoid = character.Humanoid
11            end
12        end
13    end
14 
15    return humanoid
16end

In the above function, I subtract the vectors by each other to get a single vector and get it's magnitude property. This essentially gets the distance between the tip of both vectors.

1
You should probably mention that the function expects a Vector3 argument, or change the parameter to 'targetPosition' or something similar. Otherwise, good post. Sir_Melio 221 — 6y
0
Wow! Thanks. renzocedricpura 47 — 6y
0
Lol even though this is 3y old i've configured it and it worked, thanks so much man. Nothing else worked and ive been trying for a day Theultramadman 0 — 3y
Ad

Answer this question