Using lua modules

In my main.lua file i am calling the module gameFunctions.spawnText(). Later on when i press a button it calls gameFunctions.killText(), but it wont remove the text.
I am using the following code to remove the text.

txt:removeSelf()  
txt = nil  

What am i doing wrong?

Sorry for my lack of information, i trying to describe it the best i could! I seem to be doing alot of “hacking” lately and i want to know how to do it right! I hope to take an actual class soon so i understand the concepts better!
To Add: in the terminal it says the txt:removeSelf() is the problem [import]uid: 24708 topic_id: 24824 reply_id: 324824[/import]

Would be easier if you could show us more code from your gameFunctions.lua file where you add the text, remove it and how you are doing so in your main.lua (or other) file. [import]uid: 52491 topic_id: 24824 reply_id: 100766[/import]

---GameFunctions.lua  
  
function spawnText()  
  
 local fuelText = display.newText( "Fuel", 10, 0, "Helvetica", 27 )  
 fuelText:setTextColor( 0, 250, 0, 255 )  
  
  
end  
  
  
function killMain()  
 fuelText:removeSelf()  
 fuelText = nil  
end  
  

[code]
–main.lua

_G.background= display.newImage (“background.png”, _W, _H)
background.x = _W - 100
background.y = _H/2

_G.go= display.newImageRect(“GoButton.png”, 256, 256)
go.x = _W/2
go.y = _H/4
go.xScale = .75
go.yScale = .75

function loadGame(e)
if(e.phase == “began”) then
go:removeSelf()
go = nil
audio.play(swoosh)
gameFunctions.spawnText()
end
return true
end

go:addEventListener(“touch”, loadGame)

function endGame(e)
if(e.phase == “began”) then

gameFunctions.killMain()

end

end

background:addEventListener(“touch”, endGame)

[import]uid: 24708 topic_id: 24824 reply_id: 100786[/import]

Unless i’m missing something, you have’nt defined variable gameFunctions.

Also I see gameFunctions.killMain, but in GameFunctions.lua you don’t return an object, so i’d of expected killMain() to be called without the “gameFunctions.” prefix.

Or perhaps this code sample is just missing some lines? [import]uid: 118390 topic_id: 24824 reply_id: 100922[/import]