So I made a zombie who moves to kill someone he finds and there are a lot of models like Torso and other body parts it was R6 and so I wanted to return its target name but I don't know from all the parts how to choose its name.
Look at return target at line 13 where it says "return Target"
local ZombieTorso = script.Parent.Torso local ZombieHum = script.Parent.Humanoid local function Move() local Distance = 50 local Target = nil for i,v in pairs(game.Workspace:GetChildren()) do local Human = v:FindFirstChild("Humanoid") local Torso = v:FindFirstChild("UpperTorso") if Human and Torso and v ~= script.Parent then if (ZombieTorso.Position-Torso.Position).Magnitude < Distance then Target = Torso end end end return Target -- The target here is the thing I want to find its target name how can we find use the torso to find its name from all the other children's? end while wait(1) do local TargetIs = Move() print(TargetIs) if TargetIs then ZombieHum:MoveTo(ZombieTorso.Position + Vector3.new(math.random(-50,50), 0)) end end
You could use:
for i, v in pairs
and then use
if v.Name == "" -- object name
or
if v:IsA("") -- if its an instance
or both
if v:IsA("ImageButton") and v.Name == "TestButton" then
Mark as solution, follow my roblox if it helped!