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

Need help in indexing a part inside a model that has multiple names [randomly generated]?

Asked by 5 years ago
room = script.Parent.Parent.Parent

while wait(0.1) do
    if room.Human:FindFirstChildOfClass("Model") then
    script.Parent.Humanoid.LeftArm.BrickColor = BrickColor.new("Crimson")
    print("Arm")

    else
    script.Parent.Humanoid.LeftArm.BrickColor = BrickColor.new("Medium stone grey")
    print("No arm")

    end
end

In this state the script works but after changing this:

if room.Human:FindFirstChildOfClass("Model") then

to this:

if room.Human:FindFirstChildOfClass("Model").Part["Left Arm"] then

it stops working and gives an error [indexing nil value]. How can I make it work? I tried multiple indexing ways but none worked.

I want to index a body part of a humanoid model that has randomly generated name. Script checks if the humanoid has body parts and colours them [red] on a hud if they are present and [grey] if they are gone.

0
Try if room.Human:FindFirstChildOfClass("Model")["Left Arm"] then OnaKat 444 — 5y
0
Workspace.Room1.ControlPanel.Visor.Script1:8: attempt to index a nil value | still gives an error MirrorI 5 — 5y
0
That error mean it can't find something you put on line 8 in your script. OnaKat 444 — 5y

1 answer

Log in to vote
0
Answered by
Arkrei 389 Moderation Voter
5 years ago
Edited 5 years ago

GetDescendants or GetChildren with a For Loop will work, within the for loop you can use if v:IsA("Model") then to find the children or descendants which are a model or to check the name you can use if v.Name == "Name" v is an example value used in the for loop for _,v in pairs

Ad

Answer this question