So....I have 25 text buttons for my inventory system, meaning...1 function for each button if someone wants to equip something...that's 25 different functions, JUST FOR EQUIPPING, not even for clicking Rightmousebutton. So is there a way around this? at all without having to type 50 functions?
To accomplish this, we can hold all the buttons in a central place (i.e. in a ScreenGui
) and we can loop through them. Then, we can connect an event to them. Here's an example.
local Players = game:GetService("Players") local player = Players.LocalPlayer local PlayerGui = player:WaitForChild("PlayerGui") local MainMenu = PlayerGui:WaitForChild("MainMenu") --you could just have the local script inside the main menu, but whatever for _,v in pairs(MainMenu:GetChildren()) do if v:IsA("TextButton") then v.MouseButton1Click:Connect(function() print(v.Name .. " was clicked!") end) end end)
The usage will obviously vary depending on your situation. You didn't give much detail, so I can't include much more in this answer. Good luck!