We have some buttons in GUI.
When any button is pressed the function is played but script need to know what button is.
How?
local function Nuh(Button)
print(Button.Name) --error
end
script.Parent.Slots.Slot1.MouseButton1Click:Connect(Nuh)
script.Parent.Slots.Slot2.MouseButton1Click:Connect(Nuh)
script.Parent.Slots.Slot3.MouseButton1Click:Connect(Nuh)
I don’t think it’s possible to pass a variable to a function that is connected in this way, Correct me if I am wrong, but I think what needs to happen is this:
local function Nuh(Button)
print(Button.Name)
end
script.Parent.Slots.Slot1.MouseButton1Click:Connect(function()
Nuh(script.Parent.Slots.Slot1)
end)
We can make variables and functions easily, we can even pass them around:
local Number = 2
local function Doubler(variable)
return variable*2
end
local DoubleTheNumber=Doubler(Number)
print(DoubleTheNumber)--Prints 4
We pass the Number Variable to the function, and get its output.
What we are doing in the previous code I sent is attaching the MouseButton1Click to a new function
Then we pass to Nuh the new variable which is the script.Parent.Slots.Slot1, this is the slot1 object. That gets assigned to variable Button and then we simply print the name. You can change which name gets printed easily by simply changing this:
Nuh(script.Parent.Slots.Slot1)
To this:
Nuh(script.Parent.Slots.Slot2)
I recommend this video to learn more about Events and :Connect()