I would like to know if there’s a easier way to do the same function but in a more nicer or organized way in a GUI localscript rather than having to repeat this process.
Sure there’s a easier and faster way to do this right?
I would like to know if there’s a easier way to do the same function but in a more nicer or organized way in a GUI localscript rather than having to repeat this process.
Sure there’s a easier and faster way to do this right?
Loop through the numbers and retrieve the buttons by their names.
for i = 0, 9 do
local button = numpadFrame:WaitForChild(`Numkey{i}`)
button.Activated:Connect(playBeep)
end
Thanks for the help, but I don’t think I put the code in right. I got the following error:
NumKey0 is not a valid member of Frame “Players.ObnoxiousMate.PlayerGui.KeypadGUI.BackgroundFrame.NumpadFrame”
Use Numkey instead of NumKey. I updated my code.
Should’ve known, thank you so much for the help!
Could just use GetChildren and check if the child is a TextButton instance.
I did that initially, but it’s cleaner to loop over the numbers and avoid an unnecessary check
The client should still be doing the following to account for unforeseen replication delays.
local button = frame:FindFirstChild("Button"..index)
if button then
That’s true, I’ll add a :WaitForChild instead so the button is accounted for when it loads in.
I personally dislike WaitForChild so I’d do the following, but to each their own.
local function onChildAdded(button)
button.MouseButton1Click:Connect(func)
end
frame.ChildAdded:Connect(onChildAdded) --listen to frame's child added event (for not yet replicated buttons)
--loop through buttons that have already replicated
Ahh yes UIGridLayout.MouseButton1Click
You would have to do
if button:IsA("TextButton") then
button.MouseButton1Click:Connect(func)
end
The variable names don’t even match the original script, of course you’d edit the template I provided to account for this.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.