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

Is there anything similar to FindFirstChild that doesn't require a string?

Asked by 10 years ago

Is there any other beside FindFirstChild that doesn't require a string? I need it because I want this script to work universally so I won't have to keep changing the Guis name.

Ok,so this is how the script works it finds the player distance if distance is less then 4 then it will clone the Gui into the Players Gui and then it will see if the player has the Gui by checking the Guis name,however if the the player already has a gui with the same name it won't work,is there another way to do it? The script is setup like this.

For example: Tag a object and make it find it first.

 Copy = Gui:Clone()--Tagged as Copy
                FoundCopy = Player.PlayerGui:FindFirstChild(Copy)
while wait() do
    for _,Player in pairs( game.Players:GetChildren() ) do
        -------------------------------------------------------
        local Part = script.Parent
        local Character = Player.Character
        local Distance = (Character.Torso.Position - Part.Position).magnitude
        ------------------------------------------------------- 
        print(Distance)
        if Distance < 4 then
            for _,Gui in pairs (Part.GuiFolder:GetChildren())do
                Copy = Gui:Clone()
                FoundCopy = Player.PlayerGui:FindFirstChild(Copy.Name)---Finds the Gui named "ScreenGui"
                if not FoundCopy then---Checks if the player doesn't have the gui
                    Copy.Parent = Player.PlayerGui
                end
            end
        end
    end
end

1 answer

Log in to vote
2
Answered by 10 years ago

Please upvote my rep and mark this as the correct answer if this solved/answered your question :)

To find gui in backpack:

function getGui()
    for i,v in pairs(script.Parent:GetChildren()) do
        if v:IsA("Backpack") then
            for __, gui in pairs(v:GetChildren()) do
                if v:IsA("ScreenGui") then return v end         
            end
        end
    end
end

With multiple guis:

Add a model to the gui you want to locate and then name it locateThis

function getGui()
    for i,v in pairs(script.Parent:GetChildren()) do
        if v:IsA("Backpack") then
            for __, gui in pairs(v:GetChildren()) do
                if v:IsA("ScreenGui") then
                    if gui:findFirstChild("locateThis") then
                        return v
                    end
                end         
            end
        end
    end
end
0
Agreed I was going to ask that. Here have some comment time RolandStudio 115 — 10y
0
How about now? kevinnight45 550 — 10y
0
What part are you talking about, finding the backpack in it incase you change the name, or the gui in the backpack, or both, or if the player has the gui already? Basscans 60 — 10y
0
Finding it in the backpack just in case I change the name kevinnight45 550 — 10y
View all comments (6 more)
0
Oh... updating post. Basscans 60 — 10y
0
No. To fix this you would need a BoolValue or something to verify that its that screengui. Basscans 60 — 10y
0
Will it work if It has a lot of Guis in the players backpack,and if so how would I check if the player has the specific gui so it will stop cloning? kevinnight45 550 — 10y
0
and If you can,can you add to the script? kevinnight45 550 — 10y
0
Yes. Basscans 60 — 10y
0
Oh and if I wanted to remove that specific Gui how would I remove it?Oh, and sorry for all these requests. kevinnight45 550 — 10y
Ad

Answer this question