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

Can open a GUI once, but can't open it again (From click detector) ?

Hello, i'm trying to make a customize gui for a model, and I have a click detector in the model The script in the click detector is

script.Parent.MouseClick:Connect(function(plr)
	if plr.Name == script.Parent.Parent.Parent.Door.Owner1.Value then
			game.Players[plr.Name].PlayerGui.Customize.Enabled = true
		end
end)

It opens the gui the first time, however it never opens it again after I close the menu.

Here is the script that holds the close function, if that means anything..

local red = script.Parent.Red
local orange = script.Parent.Orange
local yellow = script.Parent.Yellow
local green = script.Parent.Green
local blue = script.Parent.Blue
local purple = script.Parent.Purple
local pink = script.Parent.Pink
local preview = script.Parent.Preview
local RI = script.Parent.RInput
local GI = script.Parent.GInput
local BI = script.Parent.BInput
local R = 30
local G = 79
local B = 255



RI.Changed:Connect(function()
	if not tonumber(RI.Text) then
		if RI.Text == nil or "" then
			R = 0
			preview.BackgroundColor3 = Color3.fromRGB(R, G, B)
			preview.BorderColor3 = Color3.fromRGB(R, G, B)
		end
	else
		if tonumber(RI.Text) <= 255 and tonumber(RI.Text) >= 0 then
			R = tonumber(RI.Text)
			preview.BackgroundColor3 = Color3.fromRGB(R, G, B)
			preview.BorderColor3 = Color3.fromRGB(R, G, B)
			
		end
	end
end)
GI.Changed:Connect(function()
	if not tonumber(GI.Text) then
		if GI.Text == nil or "" then
			G = 0
			preview.BackgroundColor3 = Color3.fromRGB(R, G, B)
			preview.BorderColor3 = Color3.fromRGB(R, G, B)
		end
	else
		if tonumber(GI.Text) <= 255 and tonumber(RI.Text) >= 0 then
			G = tonumber(GI.Text)
			preview.BackgroundColor3 = Color3.fromRGB(R, G, B)
			preview.BorderColor3 = Color3.fromRGB(R, G, B)
		end
		
	end
end)
BI.Changed:Connect(function()
	if not tonumber(BI.Text) then
		if BI.Text == nil or "" then
			B = 0
			preview.BackgroundColor3 = Color3.fromRGB(R, G, B)
			preview.BorderColor3 = Color3.fromRGB(R, G, B)

		end
	else
		if tonumber(BI.Text) <= 255 and tonumber(BI.Text) >= 0 then
			B = tonumber(BI.Text)
			preview.BackgroundColor3 = Color3.fromRGB(R, G, B)
			preview.BorderColor3 = Color3.fromRGB(R, G, B)

		end
	
	end
end)
script.Parent.Close.MouseButton1Click:Connect(function()
	script.Parent.Parent.Enabled = false
end)

	
	preview.BackgroundColor3 = Color3.fromRGB(R, G, B)
	preview.BorderColor3 = Color3.fromRGB(R, G, B)

Here is the part that closes it


script.Parent.Close.MouseButton1Click:Connect(function()
	script.Parent.Parent.Enabled = false
end)

Any reason this may be happening?

3 comments

0

Oh wow, that format is hurting my eyes

0

Fixed it, some of the code blocks weren't formatting correctly

0

Why don't you set the descendant (the frame or whatever) of the ScreenGui to visible instead of enabling and disabling the ScreenGui itself? Even though it's your choice, you also have other ways of doing it. My recommendation would be to change the visibility of the Frame or the descendant instead of enabling and disabling the ScreenGui itself.

1 answer

✓ Accepted answer

Your issue is actually the fact that you open the GUI from the server but close it from the client.

What you have to do is make sure to fire a remote event to the client to open the GUI:

Server script

local OpenGuiRemote = game.ReplicatedStorage.OpenGuiRemote -- Make sure to actually add this RemoteEvent inside of ReplicatedStorage

script.Parent.MouseClick:Connect(function(player)
	if player.Name == script.Parent.Parent.Parent.Door.Owner1.Value then
		OpenGuiRemote:FireClient(player)
	end
end)

Local script:

-- This is your original close method
script.Parent.Close.MouseButton1Click:Connect(function()
	script.Parent.Parent.Enabled = false
end)

-- Just add this below it
game.ReplicatedStorage.OpenGuiRemote.OnClientEvent:Connect(function()
	script.Parent.Parent.Enabled = true
end)

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