Proximity Prompt + GUI Problem

event.OnClientEvent:Connect(function()
    print(gui.Enabled)
    gui.Enabled = true
    print(gui.Enabled)
        -- code...
end)

Proximity Prompt code:

local ProximityPromptService = game:GetService("ProximityPromptService")

local event = game:GetService("ReplicatedStorage").Events.ShowQuestionGUI

-- Detect when prompt is triggered
local function onPromptTriggered(promptObject, player)
    if promptObject.Name == "QuestAPs" then 
        event:FireClient(player)
    end
end

-- Detect when prompt hold begins
local function onPromptHoldBegan(promptObject, player)

end

-- Detect when prompt hold ends
local function onPromptHoldEnded(promptObject, player)

end

-- Connect prompt events to handling functions
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
ProximityPromptService.PromptButtonHoldBegan:Connect(onPromptHoldBegan)
ProximityPromptService.PromptButtonHoldEnded:Connect(onPromptHoldEnded)

I have a problem about my GUI, itā€™s not visibleā€¦ but I am updating it to true and nothing. (I tried on server side and client side).

image

Can you show the properties of the ProximityPrompt?

image

gui.Enabled = true

Can you explain what this line suppose to do?

is it a local script or server script

OnClientEvent:Connect

So client.

1 Like

Make the GUI visible ? ScreenGui | Roblox Creator Documentation

Iā€™m guessing.

But Enabled is not the same thing as Visible.

Yes, but itā€™s to make the GUI visible.

Is this a ScreenGUI with Frames or are you talking about the Proximity Prompt GUI?

Iā€™m guessing you want to make a GUI pop up on the screen when activating the prompt.

Can you show the hierarchy of the GUI?

Yes. https://i.gyazo.com/da7432e2232e738f2f7c99b37b77fffb.mp4
image

1 Like

The frame is visible, and when the gui is visible, itā€™s asking questions, like this: https://i.gyazo.com/da7432e2232e738f2f7c99b37b77fffb.mp4

But the problem is, the code is strange for that I mean, gui.Enabled does not work so I used RunService.Stepped:

local gui = script.Parent.Parent

local questions = {
	one = {
		q = "Are you allowed to TK",
		correct = "No",
		wrong = "Yes",
	},
	two = {
		q = "Are you allowed to RK",
		correct = "No",
		wrong = "Yes",
	},
	three = {
		q = "Who is the Premier",
		correct = "ptitloup132",
		wrong = "cenz28",
	},
	four = {
		q = "What is the first Officer Rank",
		correct = "Major",
		wrong = "Captain",
	},
	five = {
		q = "What is the first Senior Rank",
		correct = "General of the Police",
		wrong = "Marshal",
	}
}

local plr = game:GetService("Players").LocalPlayer
local event = game:GetService("ReplicatedStorage").Events.ShowQuestionGUI

event.OnClientEvent:Connect(function()
	local over = false
	
	local Stepped
	
	Stepped = game:GetService("RunService").Stepped:Connect(function()
		if not over then 
			gui.Enabled = true
		else 
			gui.Enabled = false
		end	
	end)
	
	local questionLabel = script.Parent.Question
	
	local ran = math.random(1, 5)

	local GoodAnswer = script.Parent["Answer"..math.random(1, 2)]
	local BadAnswer 

	if GoodAnswer.Name == "Answer1" then
		BadAnswer = script.Parent.Answer2
	else 
		BadAnswer = script.Parent.Answer1
	end

	if ran == 1 then 
		questionLabel.Text = questions.one.q
		GoodAnswer.Text = questions.one.correct
		BadAnswer.Text = questions.one.wrong
	elseif ran == 2 then 
		questionLabel.Text = questions.two.q
		GoodAnswer.Text = questions.two.correct
		BadAnswer.Text = questions.two.wrong
	elseif ran == 3 then
		questionLabel.Text = questions.three.q
		GoodAnswer.Text = questions.three.correct
		BadAnswer.Text = questions.three.wrong
	elseif ran == 4 then
		questionLabel.Text = questions.four.q
		GoodAnswer.Text = questions.four.correct
		BadAnswer.Text = questions.four.wrong
	elseif ran == 5 then
		questionLabel.Text = questions.five.q
		GoodAnswer.Text = questions.five.correct
		BadAnswer.Text = questions.five.wrong
	end

	for i,v in ipairs(script.Parent:GetChildren()) do 
		if v:IsA("TextButton") then 
			if v == GoodAnswer then 
				v.MouseButton1Click:Connect(function()
					game:GetService("ReplicatedStorage").Events.AddAP:FireServer(3)
					over = true
					gui.Enabled = false
					Stepped:Disconnect()
				end)
			elseif v == BadAnswer then 
				v.MouseButton1Click:Connect(function()
					over = true
					Stepped:Disconnect()
				end)
			end
		end
	end
end)

You need to make the frame visible and enable the ScreenGui both at the same time if you havenā€™t done that already.

1 Like

The frame is visible :

Hmm, can you show the definition part of the gui variable?

Wait, it works I think !

local gui = script.Parent.Parent

local questions = {
	one = {
		q = "Are you allowed to TK",
		correct = "No",
		wrong = "Yes",
	},
	two = {
		q = "Are you allowed to RK",
		correct = "No",
		wrong = "Yes",
	},
	three = {
		q = "Who is the Premier",
		correct = "ptitloup132",
		wrong = "cenz28",
	},
	four = {
		q = "What is the first Officer Rank",
		correct = "Major",
		wrong = "Captain",
	},
	five = {
		q = "What is the first Senior Rank",
		correct = "General of the Police",
		wrong = "Marshal",
	}
}

local plr = game:GetService("Players").LocalPlayer
local event = game:GetService("ReplicatedStorage").Events.ShowQuestionGUI

event.OnClientEvent:Connect(function()
	gui.Enabled = true
	gui.Frame.Visible = true
	
	local over = false
	
	local Stepped
	
	Stepped = game:GetService("RunService").Stepped:Connect(function()
		if not over then 
			--gui.Enabled = true
		else 
			--gui.Enabled = false
		end	
	end)
	
	local questionLabel = script.Parent.Question
	
	local ran = math.random(1, 5)

	local GoodAnswer = script.Parent["Answer"..math.random(1, 2)]
	local BadAnswer 

	if GoodAnswer.Name == "Answer1" then
		BadAnswer = script.Parent.Answer2
	else 
		BadAnswer = script.Parent.Answer1
	end

	if ran == 1 then 
		questionLabel.Text = questions.one.q
		GoodAnswer.Text = questions.one.correct
		BadAnswer.Text = questions.one.wrong
	elseif ran == 2 then 
		questionLabel.Text = questions.two.q
		GoodAnswer.Text = questions.two.correct
		BadAnswer.Text = questions.two.wrong
	elseif ran == 3 then
		questionLabel.Text = questions.three.q
		GoodAnswer.Text = questions.three.correct
		BadAnswer.Text = questions.three.wrong
	elseif ran == 4 then
		questionLabel.Text = questions.four.q
		GoodAnswer.Text = questions.four.correct
		BadAnswer.Text = questions.four.wrong
	elseif ran == 5 then
		questionLabel.Text = questions.five.q
		GoodAnswer.Text = questions.five.correct
		BadAnswer.Text = questions.five.wrong
	end

	for i,v in ipairs(script.Parent:GetChildren()) do 
		if v:IsA("TextButton") then 
			if v == GoodAnswer then 
				v.MouseButton1Click:Connect(function()
					game:GetService("ReplicatedStorage").Events.AddAP:FireServer(3)
					over = true
					gui.Enabled = false
					Stepped:Disconnect()
				end)
			elseif v == BadAnswer then 
				v.MouseButton1Click:Connect(function()
					over = true
					Stepped:Disconnect()
				end)
			end
		end
	end
end)
1 Like

Thank you very much, but why do I need to set the frame visible if itā€™s already visible???

1 Like

Thatā€¦ is weird. I am not completely sure, but maybe it just glitched out or something. If it works it works :smile:

1 Like