I basically made a flamethrower, and I wanted anything near a brick that has fire in it, damage something that is near it, making it seem real. However, it's not returning the humanoid in the findNearestTorso() function, and now I'm stuck! I need help with why it's not returning the humanoid. Here's the Error: 22:37:57.897 - Players.Player.Backpack.Flamethrower.Gun_Control:27: bad argument #2 to '?' (Vector3 expected, got nil) 22:37:57.898 - Script 'Players.Player.Backpack.Flamethrower.Gun_Control', Line 27 - global findNearestTorso 22:37:57.900 - Script 'Players.Player.Backpack.Flamethrower.Gun_Control', Line 55 - global MouseDown 22:37:57.901 - Script 'Players.Player.Backpack.Flamethrower.Gun_Control', Line 79 22:37:57.901 - Stack End
function findNearestTorso(pos) local list = game.Workspace:GetChildren() local torso = nil local dist = 5 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) and (temp2.Name == "LMADer") or (temp2.Name == "Vaktus") or (temp2.Name == "BC") then temp = temp2:findFirstChild("Head") human = temp2:findFirstChild("Humanoid") local player = game.Players:GetPlayerFromCharacter(temp2) if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and not player then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end elseif (temp ~= nil) and (human ~= nil) and (human.Health > 0) and player.TeamColor ~= BrickColor.new("Bright blue") then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return human end MouseDown = function(mouse) local creator = Instance.new("ObjectValue") local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent) creator.Value = plr mousedown = true if not firing then while mousedown do wait(1) firing = true fire1.Enabled = true fire2.Enabled = true fire3.Enabled = true local hum = findNearestTorso(c1.Position) creator.Parent = findNearestTorso() findNearestTorso():TakeDamage(5) end firing = false end end