I’m adding a load of buttons to the UI dynamically. I need to know which one’s been clicked, but there doesn’t seem to be anything useful in what I’m being passed.
This is a local script in my GUI. It happens to create two buttons at the moment, because that’s how many levels I’ve created for my game
local playerGUI = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local ReplicatedStorage = game:GetService("ReplicatedStorage")
function onButtonActivated(inputObject, clickCount)
print(inputObject.Name)
end
local getLevelNames = ReplicatedStorage:WaitForChild("GetLevelNames")
local levelNames = getLevelNames:InvokeServer()
for i,levelName in ipairs(levelNames) do
print(levelName)
local button = Instance.new("TextButton",playerGUI.DebugGUI)
button.Name = levelName
button.Text = levelName
button.Size = UDim2.new(0, 200, 0, 20)
button.Position = UDim2.new(0, 0, 1, -i*40)
button.Activated:Connect(onButtonActivated)
end
GetLevelNames returns an array of strings. The buttons go on the screen, they’re clickable, and I get a print when I click them.