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

How do i make a script that finds models inside your player then getting all of the children inside?

So, im trying to make a first person script that uses :IsA("") and :GetDecendants() to finds models inside your player in the workspace, then getting all of the children inside the model to manipulate a VR first person look.

heres my attempt:

local character = (game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:wait())

for i,v in pairs (character:IsA("Model")) do
	for o,b in pairs (v:GetDecendants()) do
	b.LocalTransparencyModifier = 0
	end
end

edit: grammar

edit2: variables, more specific

2 comments

0

did you define character above?

0

ah sorry about that, i edited it

1 answer

✓ Accepted answer

for i, v in pairs(parameter) do takes in a table for the parameter, try to read up on loops and navigating through tables/dictionaries to familiarize yourself with this type of code.

As for your question, I am not sure where you are searching for this object with a specific class name. I am also not sure whether you just want to find the first object that has this class name or find every object with this class name.

For my code, I will assume you are searching in the workspace and you want to find every object with this class name.

local className = "Model"
local workspaceObjects = game.Workspace:GetChildren()--this is a table of all the objects in the Workspace
for _, child in pairs(workspaceObjects) do--search through a table of objects
	if child:IsA(className) then --if the object you are currently looking at is the class you are searching for, continue
		--Do whatever it is you want with this child
	end
end

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