Skip to content

GUI Events

Patrick Miller edited this page Jul 17, 2026 · 1 revision

GUI Opening and Closing

There are two sections available that allow you to run code whenever the GUI is opened and whenever it is closed:

run (when|while) (open[ing]|clos(e|ing)) [[the] gui]
run (when|while) [the] gui (opens|closes)
run on [gui] (open[ing]|clos(e|ing))

For example, we could prevent the player from being damaged while they have the GUI open:

command /protectedgui:
	trigger:
		create a gui with a virtual chest inventory named "Protected GUI":
			run on open:
				make the player invulnerable
			run on close:
				make the player vulnerable
		open the last created gui for the player

Cancelling GUI Closing

It is also possible to prevent the user from closing the GUI by using the cancel gui close effect:

(cancel|uncancel) [the] gui clos(e|ing)

For example, we could make a game that requires the user to click five times before they can close the GUI:

command /cookieclicker:
	trigger:
		set {-clicks::%player%} to 0
		create a gui with a virtual dispenser inventory named "<brown><bold>Cookie Clicker":
			make gui slot 4 with a cookie named "<brown>Clicks: %{-clicks::%player%}%":
				add 1 to {-clicks::%player%}
				set the name of the gui clicked item to "<brown>Clicks: %{-clicks::%player%}%"
			run on close:
				if {-clicks::%player%} is less than 5:
					cancel the gui closing
		open the last created gui for the player
skript-gui-cookie-clicker.mov

GUI Slot Change

Caution

Coming Soon

Clone this wiki locally