Gui script does not think its a gui script

while making a healthbar for my game, I use the line
local health1 = gui.get_node(heart1)
however for some reason it keeps crashing saying you can only access gui functions and values from a gui script instance, i’ve made sure im using a .gui_script file to write the code and it is even attached to the healthbar, what am i doing wrong

Can you post the script file contents?

I suspect you have placed the line outside of the lifecycle functions.

This will not work:

local health1 = gui.get_node("heart1")

function init(self)

end

This should work:

function init(self)

local health1 = gui.get_node("heart1")

end
5 Likes