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

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

Asked by 4 years ago
Edited 4 years ago

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

0
did you define character above? iiClearlyDeveloper 59 — 4y
0
ah sorry about that, i edited it iiAwishkle 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question