Lua 72: attempt to index global 'GUI' (a nil value)

i keep on getting this message:

Lua 72: attempt to index global ‘GUI’ (a nil value)

display.setStatusBar(display.HiddenStatusBar) local physics = require "physics" physics.start() physics.setGravity(0,0) local \_score = 0; --load your sound effect near the beginning of your file local myTheme = audio.loadSound("theme.mp3") --To play the sound effect, call this whenever you want to play it audio.play(myTheme) -- SETUP GRAPHICS local background = display.newImage("bg.png") local happy = display.newImage("jawad.png") happy.x = 100 happy.y = 100 physics.addBody(happy, "dynamic") local angry = display.newImage("pig.png") angry.x = 880 angry.y = 560 physics.addBody(angry, "static") local angry2 = display.newImage("pig.png") angry2.x = 840 angry2.y = 520 physics.addBody(angry2, "static") -- RESPOND TO TOUCH EVENTS function touchScreen(event) if event.phase == "ended" then transition.to(happy,{time=1000, x=event.x, y=event.y}) end end Runtime:addEventListener("touch", touchScreen) -- CREATE ANGRY MOVEMENT function moveAngry() transition.to(angry,{time=1000, x=math.random(80,880), y=math.random(60,580), onComplete=moveAngry}) transition.to(angry2,{time=1000, x=math.random(80,880), y=math.random(60,580)}) end moveAngry() -- RESPOND TO COLLISIONS function onCollision(event) --print("collide!") happy:removeSelf() end Runtime:addEventListener("collision", onCollision) local score\_txt = display.newText(" SCORE: ", 0, 0, "Komika Axis", 36); score\_txt.x = (score\_txt.width \* 0.5) + 20; score\_txt.y = (score.txt.height \* 0.5) +4; local score = display.newText(" " .. \_score, 0, 0, "Komika Axis", 36); score:setReferencePoint(display.CenterLeftReferencePoint); score.x = scoreLeftX; score.y = score\_txt.y; score\_txt:setTextColor(3, 3, 3); score:setTextColor(3, 3, 3); GUI:insert(score\_txt) return Scene

Game without:

local score_txt = display.newText(" SCORE: ", 0, 0, “Komika Axis”, 36);
score_txt.x = (score_txt.width * 0.5) + 20; score_txt.y = (score.txt.height * 0.5) +4;

local score = display.newText(" " … _score, 0, 0, “Komika Axis”, 36);
    score:setReferencePoint(display.CenterLeftReferencePoint);
    score.x = scoreLeftX; score.y = score_txt.y;
    
    score_txt:setTextColor(3, 3, 3);
    score:setTextColor(3, 3, 3);
    
    GUI:insert(score_txt)
    
return Scene

P879O.png

game with the code:

nWYTb.png

Thanks…

You seem to be inserting into GUI display group but I do not see GUI = display.newGroup() anywhere in the code provided…

can you edit the line i had wrong please

You can try adding

[lua]

local GUI = display.newGroup()

[/lua]

on line 61.

You seem to be inserting into GUI display group but I do not see GUI = display.newGroup() anywhere in the code provided…

can you edit the line i had wrong please

You can try adding

[lua]

local GUI = display.newGroup()

[/lua]

on line 61.