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

GUi for each item in folder is this possible?

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

2 comments

0

Gui.Name = v

0

sorry please read my answer.

2 answers

✓ Accepted answer

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

4 comments

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.

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.

0

I can't believe I didn't notice that from script.Parent, my bad.

0

I moved the script out of the thing and changed it a bit and it worked thanks.

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.

2 comments

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.

0

8 & 9 of your second loop are syntactically incorrect. It's Weapons[i].Name

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