hello, i am new to returning and i need some help with it. i am currently making an AI and i need some help with returning two variables, the target humanoid and the target humanoid root part. i want these two values to be returned to a new function but it says the value i am trying to access is unknown, this probably means it is a problem with scope, which i am also not very good at.
local animatronic = script.Parent
local animatronicHumanoidRootPart = animatronic:FindFirstChild("HumanoidRootPart")
local animatronicHumanoid = animatronic:FindFirstChild("Humanoid")
local function findTarget()
print(1)
for i, players in pairs (game.Players:GetPlayers()) do
local targetCharacter = players.Character or players.CharacterAdded:Wait()
if targetCharacter then
local targetHumanoidRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
local targetHumanoid = targetCharacter:FindFirstChild("Humanoid")
if targetHumanoidRootPart then
if targetHumanoid then
if (targetHumanoidRootPart.Position - animatronicHumanoidRootPart.Position). magnitude < 100 and targetHumanoid.Health > 0 then
return targetHumanoid, targetHumanoidRootPart -- returning the values. im not sure how to return multiple values, i assume this is how you do it though
end
end
end
end
end
end
local function noTarget()
findTarget() -- the value function thats returning the values
end
local function followTarget()
local targetHumanoid = findTarget(targetHumanoid) -- accessing the variables gives me the unknown error, im only trying to access one at the moment
end
while wait(5) do
end

1 comment
i changed this ~~~~~~~~ local targetHumanoid, targetRoot = findTarget(targetHumanoid, targetHumanoidRootPart) ~~~~~~~~~~~ and it still comes up with the Unknown error in the output