fairyoggy Posted April 30, 2022 Posted April 30, 2022 How can I define a button for a function? function test1() window1test1 = guiCreateWindow((sW - 419) / 2, (sH - 165) / 2, 280, 310, "test1", false) local button1 = guiCreateButton ( 5, 25, 120, 25, "btn1", false, window1test1) addEventHandler("onClientGUIClick",button1,test2,false) end addEvent("test1", true) addEventHandler("test1", root, test1) addCommandHandler("test1",test1) function test2() guiSetEnabled (button1,false) end [Expected gui-element at argument 1, got nil] At the moment, I'm getting an error because it can't find the button, how fix?
Hydra Posted April 30, 2022 Posted April 30, 2022 (edited) function buttonClick() if source == button1 then iprint("You clicked me") end addEventHandler("onClientGUIClick", root, buttonClick) or function buttonClick() iprint("You clicked me") addEventHandler("onClientGUIClick", button1, buttonClick) Edited April 30, 2022 by Hydra Social Media: Discord: Gabriel45#6859 Instagram: https://www.instagram.com/_gabriel_455/ YouTube: Hydra45 (https://www.youtube.com/c/Hydra45/)
fairyoggy Posted April 30, 2022 Author Posted April 30, 2022 7 minutes ago, Hydra said: function buttonClick() if source == button1 then iprint("You clicked me") end addEventHandler("onClientGUIClick", root, buttonClick) or function buttonClick() iprint("You clicked me") addEventHandler("onClientGUIClick", button1, buttonClick) you didn’t understand, the button action works, but I need the button to enabled off when pressed, but if I use my code, i have error: "[Expected gui-element at argument 1, got nil] " in line: guiSetEnabled (button1,false)
Hydra Posted April 30, 2022 Posted April 30, 2022 1 hour ago, fairyoggy said: you didn’t understand, the button action works, but I need the button to enabled off when pressed, but if I use my code, i have error: "[Expected gui-element at argument 1, got nil] " in line: guiSetEnabled (button1,false) Yea, sorry Try to do it like this local button1 function test1() window1test1 = guiCreateWindow((sW - 419) / 2, (sH - 165) / 2, 280, 310, "test1", false) button1 = guiCreateButton ( 5, 25, 120, 25, "btn1", false, window1test1) addEventHandler("onClientGUIClick", root, test2) end addEvent("test1", true) addEventHandler("test1", root, test1) addCommandHandler("test1",test1) function test2() if source == button1 then guiSetEnabled (button1,false) removeEventHandler("onClientGUIClick", root, test2) end end 1 Social Media: Discord: Gabriel45#6859 Instagram: https://www.instagram.com/_gabriel_455/ YouTube: Hydra45 (https://www.youtube.com/c/Hydra45/)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now