Hello, I am trying to clone multiple of the “Slots” in my game into a GUI however it’s only cloning one, but I have tested it and the loop works perfectly fine. I have been working on it for around an hour seeing why it’s doing this and I don’t know still. I want to know how to get the script to clone the GUI based on how much materials is in the table? right now it’s two and I only get one GUI. I’ve looked on some of my previous games to see the code, I’ve searched the answers online and looked at the Developer Hub. Can someone please help me? I would be greatly appreciated.
local forge = {}
--Events
local ReplicatedStorage = game:FindService("ReplicatedStorage")
local MaterialOne = ReplicatedStorage.Events:FindFirstChild("MaterialOne")
local MaterialTwo = ReplicatedStorage.Events:FindFirstChild("MaterialTwo")
local FindPlayer = ReplicatedStorage.Events:FindFirstChild("FindPlayer")
--Other Variables
local Slot = ReplicatedStorage.SlotItems:FindFirstChild("Slot"):Clone()
--Actual Code
FindPlayer.OnServerEvent:Connect(function(playernme)
local slots = {"Iron","Iron"}
print(playernme.Name)
for i, v in pairs(slots) do
local deb = false
if v ~= nil and deb == false then
deb = true
if v == "Iron" then
Slot.Parent = game:FindService("Players")[playernme.Name]:FindFirstChild("PlayerGui").MaterialPick:WaitForChild("Frame")
Slot.Name = "Iron"..i
wait(0.1)
end
else
break
end
deb = false
end
end)
return forge
This is a module script and the loop is activated when the player opens the GUI and the Remote event is fired to the server.
What does the gui look like when this function runs, does anything yield (perhaps infinitely)?
Checked if you perhaps got a variable name wrong? (Happened to me often.)
You only made 1 clone, outside of the loop. The result is you keep reparenting it to the new parent, not creating a new one. So, you only get a slot for the the final item in the loop.
Fixed code:
omeone please help me? I would be greatly appreciated.
local forge = {}
--Events
local ReplicatedStorage = game:FindService("ReplicatedStorage")
local MaterialOne = ReplicatedStorage.Events:FindFirstChild("MaterialOne")
local MaterialTwo = ReplicatedStorage.Events:FindFirstChild("MaterialTwo")
local FindPlayer = ReplicatedStorage.Events:FindFirstChild("FindPlayer")
--Other Variables
--Removed slot clone from here
--Actual Code
FindPlayer.OnServerEvent:Connect(function(playernme)
local slots = {"Iron","Iron"}
print(playernme.Name)
for i, v in pairs(slots) do
local deb = false
if v ~= nil and deb == false then
deb = true
if v == "Iron" then
--Create the slot here instead
local Slot = ReplicatedStorage.SlotItems:FindFirstChild("Slot"):Clone()
Slot.Parent = game:FindService("Players")[playernme.Name]:FindFirstChild("PlayerGui").MaterialPick:WaitForChild("Frame")
Slot.Name = "Iron"..i
wait(0.1)
end
else
break
end
deb = false
end
end)
return forge