Recently i’ve made a GUI for only the creator/s, this GUI would create for every administrator a card inside a ScrollingGui, each card has a button to fill out the text of a TextBox
(this button is the one not working), the card template is stored inside a folder and gets cloned for each value inside the Admins
table.
Button Script
for index,value in ipairs(script.Parent.HolderFrame.ScrollingFrame:GetChildren()) do
value.Button.MouseButton1Down:Connect(function()
print("Button pressed for: ".. value.Name)
if IsOpen then
HolderFrame.SelectedBox.Holder.TextBox.Text = value.Name
else
print("IsOpen: false")
end
end)
end
I honestly do not know why this doesn’t work as it worked before, it also does not print anything, not the print statements nor any errors.
Pictures
Have you checked to make sure the button script runs after all the admin cards are made? If the event script runs before the cards are made, :GetChildren()
would return an empty array.
If this is the problem, a simple fix would be connecting to a .ChildAdded
event:
local cardFrame = script.Parent.HolderFrame.ScrollingFrame
local function connectMouse(card)
card.Button.MouseButton1Down:Connect(function()
print("Button pressed for: ".. value.Name)
if IsOpen then
HolderFrame.SelectedBox.Holder.TextBox.Text = value.Name
else
print("IsOpen: false")
end
end)
end
for _, card in ipairs(cardFrame:GetChildren()) do
connectMouse(card)
end
cardFrame.ChildAdded:Connect(connectMouse)
Another solution would be making the event script run after the id card creation script by using a BindableEvent
or a ModuleScript
.
1 Like