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
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 variablei
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
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.