fairyoggy Posted April 30, 2022 Share 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? Link to comment
Hydra Posted April 30, 2022 Share 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 Link to comment
fairyoggy Posted April 30, 2022 Author Share 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) Link to comment
mafioz Posted April 30, 2022 Share Posted April 30, 2022 guiSetProperty( button1, "Disabled", "True" ) Link to comment
Hydra Posted April 30, 2022 Share 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 Link to comment
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