Hey!
I’m making a auto-aim skill for my game and I’m having some trouble getting the Projectile to go towards the nearest player.
local function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 75
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.ClassName == "Model") and (temp2 ~= plr.Character) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - plr.Character.HumanoidRootPart.Position).Magnitude < dist then
torso = temp
dist = (temp.Position - plr.Character.HumanoidRootPart.Position).Magnitude
end
end
end
end
return torso
end
local Projectile = game.ReplicatedStorage.DokuDF.Auto:Clone()
Projectile.Parent = workspace
Projectile.CanCollide = false
Projectile.Anchored = false
Projectile.CFrame = plr.Character.HumanoidRootPart.CFrame
local target = findNearestTorso(plr.Character.HumanoidRootPart.Position)
local char = plr.Character
local PlayerHumanoid = plr.Character:WaitForChild("HumanoidRootPart")
local TargetHumanoid = target
local eChar = target.Parent
local AAim = Instance.new("RocketPropulsion")
AAim.Parent = Projectile
AAim.Target = Target
AAim:Fire()
Target is not Nil so I’m having some trouble on why it is not moving.