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

GUi for each item in folder is this possible?

Asked by 3 years ago
Edited 3 years ago

It goes through a folder called "Weapons" and for each item in it I want it to make a GUI, Set the name and text to the name of the weapon then make it visible. It dose not work and there are no errors.

local repStor = game:GetService("ReplicatedStorage")

local Wepons = repStor:FindFirstChild("Weapons")

for i,v in pairs(Wepons:GetChildren()) do
    local Gui = script.Parent:Clone()
    Gui.Name = i
    Gui.Text = i
    Gui.Visible = true
end
0
Gui.Name = v WINDOWS10XPRO 438 — 3y
0
sorry please read my answer. WINDOWS10XPRO 438 — 3y

2 answers

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

There should be quite the number of errors, you must be using the incorrect Script type, or have it under a container that doesn't execute programs.

Let's list off the things you need to fix:

You're traversing through an array, therefore index-pairs is best suited for iteration.

The variable i refers to the current index, you'll get an integer instead of a string.

You created a clone and gave it no Parent.

You're not referencing the .Name property, you'll get two errors.

--###----------[[VARIABLES]]----------###--
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Weapons = ReplicatedStorage:WaitForChild("Weapons")


local GUITemplate = script.Parent



--###----------[[LOGIC]]----------###--
for _, Weapon in ipairs(Weapons:GetChildren()) do
    local GUI = GUITemplate:Clone()
    ---------------
    GUI.Name = Weapon.Name
    GUI.Text = Weapon.Name
    GUI.Visible = true
    ---------------
    GUI.Parent = --// Location.
end
0
Sorry for accept then unaccept. I saw a few problems. It kept looping so its a inf loop of them. So it gose through then keeps going through making it a inf loop of GUI's then I have a red text error saying "starScript re-entrancy has exceeded 3" on line 14. Ems_Squad 58 — 3y
0
Judging from the context of what you've just said, this script is a child of the Instance you're cloning. This means that it will spawn the same code indefinitely, which explains your issue. To resolve this, obviously, move the Script outside of the Instance to be cloned. Ziffixture 6913 — 3y
0
I can't believe I didn't notice that from script.Parent, my bad. Ziffixture 6913 — 3y
0
I moved the script out of the thing and changed it a bit and it worked thanks. Ems_Squad 58 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local repStor = game:GetService("ReplicatedStorage")

local Wepons = repStor:FindFirstChild("Weapons")

for i,v in pairs(Wepons:GetChildren()) do
    local Gui = script.Parent:Clone()
    Gui.Name = v.Name
    Gui.Text = v.Name
    Gui.Visible = true
end

you make it i instead of v and you must put the Name or else the script won't understand what you wanted. If it keeps on looping then try this one

local repStor = game:GetService("ReplicatedStorage")
local Wepons = repStor:FindFirstChild("Weapons"):GetChildren()

for i=1, #Wepons do
    local Gui = script.Parent:Clone()
    Gui.Parent = game.Players.LocalPlayer:WaitForChild("Backpack")
    Gui.Visible = false
    Gui.Name = i[Wepons].Nane
    Gui.Text = i[Wepons].Name
    Gui.Visible = true
end

if it doesn't work please dm me on discord Blue Duck#9891 and try to be as specific as you can. Stay safe.

0
Both of these loops are only capable of iterating to n# of assets in "Weapons". There is no such perpetuation caused by the loop itself. It's instructions, however, is causing the contradiction. Found on lines 5 & 6. Ziffixture 6913 — 3y
0
8 & 9 of your second loop are syntactically incorrect. It's Weapons[i].Name Ziffixture 6913 — 3y

Answer this question