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

Trying to fix folder heirarchy and :FindFirstChild searching, can anyone help?

Asked by 4 years ago

So, I have a hierarchy of folders, and because I have no clue how to insert pics here, ill just type it out lol.

ReplicatedStorage Folder1 Folder2 Folder3 Model

And I am trying to make a developer gui where I can spawn in items from repstorage. I have a textbox where I type what I want to spawn, then it searches folder1 using :FindFirstChild and looks for what I typed in the textbox. But, because of the folder layers (for organization) it wont work. Does anyone know a fix for this?

Code:

script.Parent.MouseButton1Click:Connect(function()
    local player = game.Players.LocalPlayer
    local human = player.Character
    local torso = human.UpperTorso
    local newInstance = game.ReplicatedStorage.SandboxInstances:WaitForChild(script.Parent.Parent.TextBox.Text)
    if newInstance then
        local clone = newInstance:Clone()
        clone.Parent = workspace
        clone.PrimaryPart = clone.Base
        clone:SetPrimaryPartCFrame(torso.CFrame + torso.CFrame.lookVector * 10)
    else
        warn("Instance not found!")
    end
end)
0
Commenters: Please press "View Source" because some of the code got cut off in the block for some reason IAmRandomPlayer8263 15 — 4y

1 answer

Log in to vote
1
Answered by
Nckripted 580 Moderation Voter
4 years ago

NOTE: I'm just basing this off of what I understood from your post, as this was very unclear.

What might help is the :GetDescendants method, which essentially gets the children and those objects' children and so on, and returns a table of all these instances.

Ad

Answer this question