GUI Won't Appear

Hi, there fellow developer. I have a part that makes a gui appear when a player touches it. This works fine, however it doesn’t work anymore after the player first opens it and closes it. I can’t take videos on my mac so you can try it to so what I mean. (Sorry)
GO HERE

!
THEN HERE

Script to make the gui appear
script.Parent.MouseButton1Click:Connect(function()

game.Players.LocalPlayer.PlayerGui.ColorBlindTest.Enabled = false

game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.Enabled = true

game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.TestEnd.Visible = false

end)

Let me know if you want to see any other scripts or have questions, thanks.

Can you give us the code for disabling the GUI?

Yes, can you also provide any errors that occur? Where the script is located? What script it is?

1 Like

Can you give more of a detailed description of how this works? Because all I’m seeing right now is when you click the part it makes ColorBlind and TestEnd hidden and the LockScreenTest visible.

No errors are shown in the output the script is located under a text button in a frame under a ScreenGui, it’s a local script.

This is the whole script that is used in the gui
local questions = {
{“Red”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},1},
{“Orange”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},2},
{“Yellow”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},3},
{“Green”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},4},
{“Blue”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},5},
{“Purple”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},6}
}

local numberCorrect = 0
local NumberOfQuestions = 6


local function finish()
	local percentCorrect = math.floor(numberCorrect/NumberOfQuestions * 100)

 --DISABLES THE GUI

game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.TestEnd.Visible = true
game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.TestEnd.Number.Text = percentCorrect

end


local Question, Answers, CorrectAnswer
local function changeQuestion()
	-- load question
	local TempQuestionNumber = math.random(1,#questions)
	local QuestionData = questions[TempQuestionNumber]
	Question, Answers, CorrectAnswer = unpack(QuestionData)
	
	-- Set all frames visibility to false
	local UI_objs=script.Parent.Frame:GetChildren()
	for i,obj in pairs(UI_objs) do
		if (obj:IsA('Frame')) then
			obj.Visible=false
		end
	end
	
	-- Set the corresponding frame's visibility to true if it exists
	if script.Parent.Frame:FindFirstChild(Answers[CorrectAnswer]) then
		script.Parent.Frame:FindFirstChild(Answers[CorrectAnswer]).Visible=true
	end
	
	table.remove(questions,TempQuestionNumber)
end


local function answer(name) 
	if string.match(name, Answers[CorrectAnswer]) then	-- If button name contains answer than mark correct; works within this specific context, may not work for another
		numberCorrect = numberCorrect+1
	end
	
	if #questions<=0 then	-- If all questions are taken then finish test
		finish()
	else
		changeQuestion()	-- Otherwise change question
	end
end

-- Connect all buttons to answer function
local UI_objs=script.Parent.Frame:GetChildren()
for i,obj in pairs(UI_objs) do
	if (obj:IsA('TextButton')) then
		obj.MouseButton1Click:Connect(function () answer(obj.Name) end)
	end
end

changeQuestion()

Then you take a test and after the test LockScreenTest is set to false and a new gui is set to visible. Then when you click a text button that gui is set to false. When you touch the part again ColorBlind is enabled, but when you click the next button nothing else appears.

I’m assuming you’re doing this in a LocalScript in a part in workspace. Move the LocalScript to a place where it will run, such as StarterPlayerScripts, and see what happens.

The script is in StarterGui and it works, but then it stops working.

I just noticed, I confused the mouseButton1Click event with a ClickDetector. Whoops!

Looking at it more carefully, I think the problem here is that when the player clicks a button, Gui gets enabled and disabled, but it stays that way no matter what. this is because when the player clicks it, whatever becomes enabled always is enabled, because you’re always making enabled true. What you need to do is make an if statement, checking whether something is enabled or not, then enabling and disabling Gui based on that.

Im confused by what you mean, can you please give an example.

if screenGui.Enabled == true then --Change true to false if you wish
    --Code
else
    --Code for when it isn't enabled
end

It’s better to do

screenGui.Enabled = not screenGui.Enabled
1 Like