I am having trouble with my script
script.Parent.MouseButton1Click:Connect(function) print(“Click”) end)
You use (function()
script.Parent.MouseButton1Click:Connect(function() print(“Click”) end)
It depends on where you have your script.
If you have your script inside of the TextButton or ImageButton, then it should work. Just fix your first line to be this:
script.Parent.MouseButton1Click:Connect(function() --// Script is inside of TextButton or ImageButton. --// Code to be fired when the button is clicked end)
If it's not inside of it, you would have to reference the TextButton or ImageButton, otherwise it won't work. No other GUI element has the ability to be clicked and react as a function. So you would have to do this:
script.Parent.TextButton.MouseButton1Click:Connect(function() --// Change this to the location of where the button is located at. This script is not inside of the TextButton or ImageButton. --// Code to be fired when the button is clicked end)
It really all depends on how you have your GUI and Scripts setup.
Hope this helped! If you have anymore questions comment down below and I'll try to help you out as much as I can! If this worked, select this as the answer so everyone else knows this question has been solved. If it didn't work, comment down below what went wrong with a picture of how you have your GUI setup so it will be easier to figure this out. Glad to be of help!
~killerbrenden
You put the function inside the brackets! That is why! This should work:
function onClicked() print("Click") end script.Parent.MouseButton1Click:Connect(onClicked)