freudo Posted February 20, 2015 Share Posted February 20, 2015 Hi guys I write this code: addEventHandler("onClientResourceStart", resourceRoot, function() onoff = guiCreateStaticImage(578, 290, 138, 34, "img/off.png", false) showCursor(true) end ) function click() if (source == onoff) then guiStaticImageLoadImage(onoff, "img/on.png") elseif (source == onoff) then guiStaticImageLoadImage(onoff, "img/off.png") end end addEventHandler("onClientGUIClick",root,click) I click onoff button and load on button again ı want click and load on button pls help Link to comment
Dealman Posted February 20, 2015 Share Posted February 20, 2015 The first if statement will always be true, it will never run the 2nd one. You'll have to assign a variable; local isButtonOn = false; function click() if (source == onoff and isButtonOn == false) then guiStaticImageLoadImage(onoff, "img/on.png") elseif (source == onoff and isButtonOn == true) then guiStaticImageLoadImage(onoff, "img/off.png") end end addEventHandler("onClientGUIClick",root,click) Link to comment
Dealman Posted February 20, 2015 Share Posted February 20, 2015 Just noticed I forgot to update the variable too, my bad; local isButtonOn = false; function click() if (source == onoff and isButtonOn == false) then guiStaticImageLoadImage(onoff, "img/on.png") isButtonOn = true elseif (source == onoff and isButtonOn == true) then guiStaticImageLoadImage(onoff, "img/off.png") isButtonOn = false end end addEventHandler("onClientGUIClick",root,click) But maybe you figured it out already 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