Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

if statement not running global functions?

i have 2 pieces of code, this:

--textscenes
-- the file used to control the chat function

_G.wt1 = false
_G.wt3 = false

_G["WelcomeText1"] = function()
local p = game.Players:GetChildren()
_G.openChat()
	for i = 1, #p do
		_G.showspacebarchat()
		p[i].PlayerGui.Chat.ChatWindow.ChatText.Text = "Welcome to Roblox Party!"
		_G.talkExcitedUltraTechX:Play()
		_G.talkExcitedValien:Play()
	end
	wait(0.25)
	_G.wt1 = true
end
	
	
_G["WelcomeText2"] = function()
	local p = game.Players:GetChildren()
	for i = 1, #p do
		_G.hidespacebarchat()
	p[i].PlayerGui.Chat.ChatWindow.ChatText.Text = "what board would you like to play on?"
	_G.talkExplainUltraTechX:Play()
		_G.talkExplainValien:Play()
	end
	
	_G.showBoardSelection();
	
end

_G["WelcomeText3"] = function()
	local p = game.Players:GetChildren()
	for i = 1, #p do
		_G.showspacebarchat()
		p[i].PlayerGui.Chat.ChatWindow.ChatText.Text = "alrighty then, lets go to ".._G.board.." land".."!"
		_G.talkExcitedUltraTechX:Play()
		_G.talkExcitedValien:Play()
	end
	wait(0.25)
	_G.wt3 = true
end

_G["WelcomeText4"] = function()
	local p = game.Players:GetChildren()
	_G.closeChat()
	for i = 1, #p do
		_G.hidespacebarchat()
		
	_G.creategoToPortal()
	_G.enablegoToPortal()
	
	end
	
end

and this file:

--keyhandler
--modulescript code:
local module = {}

function module.onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Space then
        print("Spacebar was pressed")
        if(_G.wt1 == true) then
            _G.wt1 = false
            _G.WelcomeText2()
        elseif(_G.wt3 == true) then
            _G.wt3 = false
            _G.WelcomeText4()       
        end     
    end
end

return module

this code works in studio, but not in the real game. Why is this not working? Thanks in advance.

1 comment

0

Usually something not working in online is because your script tries to access something that hasn't loaded yet (solve this by using :WaitForChild). You can see where the error occurs by looking through the developer console (F9).

1 answer

There's two reasons this could be erroring, you'll need to add a WaitForChild or either you added something there that only localscripts can detect.

1 comment

0

@RevergeHelps here is a picture of it after adding waitforchild() : http://imgur.com/7Gf1PSj This Makes me thing it has something to do with the _G variables and functions, is that possibly the case?

This discussion is preserved as it was. New answers, comments, and votes are closed.