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

How to Pick Specific Thing from other Children?

Asked by 4 years ago
Edited 4 years ago

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"

01local ZombieTorso = script.Parent.Torso
02local ZombieHum = script.Parent.Humanoid
03 
04local function Move()
05    local Distance = 50
06    local Target = nil
07    for i,v in pairs(game.Workspace:GetChildren()) do
08        local Human = v:FindFirstChild("Humanoid")
09        local Torso = v:FindFirstChild("UpperTorso")
10 
11        if Human and Torso and v ~= script.Parent then
12            if (ZombieTorso.Position-Torso.Position).Magnitude < Distance then
13                     Target = Torso            
14            end
15        end
View all 26 lines...

1 answer

Log in to vote
1
Answered by 4 years ago

You could use:

1for i, v in pairs

and then use

1if v.Name == "" -- object name

or

1if v:IsA("") -- if its an instance

or both

1if v:IsA("ImageButton") and v.Name == "TestButton" then

Mark as solution, follow my roblox if it helped!

Ad

Answer this question