Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

3 comments

0

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

0

Workspace.Room1.ControlPanel.Visor.Script1:8: attempt to index a nil value | still gives an error

0

That error mean it can't find something you put on line 8 in your script.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.