GUI not appearing in this script

To put it simply, Fram.Visible is not appearing when I want it to appear. What is wrong with this code?

local gui =  game.Players.LocalPlayer.PlayerGui:WaitForChild("buy").Frame
local part = workspace.click.ClickDetector
local Owns = game.Players.LocalPlayer.PlayerGui:WaitForChild("buy").Frame.Owns
local Fram = game.Players.LocalPlayer.PlayerGui:WaitForChild("main").Frame

part.MouseClick:Connect(function()
	gui.Visible = true
end)
if part.MouseClick and Owns.Value == true
then 
	gui.Visible = false
	Fram.Visible = true
end

Do the gui.Visible = true and gui.Visible = false both work?

part.MouseClick:Connect(function()
	gui.Visible = true
end)

This statement works.

There could be a lot of problems with your code and even in your gui’s. one thing I would like to point out real quick is to make it easier to define your things. You could easily set it up like this:

local playergui = game.Players.LocalPlayer.PlayerGui
local gui = playergui:WaitForChild("buy")
local guiFrame = gui.Frame
local Owns = gui.Frame.Owns
local Fram = playergui:WaitForChild("main").Frame

Now to actually get to one problem, make sure your owns value is true. you can check it by printing the value before checking the value.

print(Owns.Value)

1 Like

If the “gui” doesn’t disappear its probably an issue with the Owns.Value

The Owns.Value is set to true when clicked. But the Fram GUI does not appear when clicked a second time.

Where do you set the value to true?

this is the updated script: Is it good?

local playergui = game.Players.LocalPlayer.PlayerGui
local gui = playergui:WaitForChild("buy")
local guiFrame = gui.Frame
local Owns = gui.Frame.Owns
local Fram = playergui:WaitForChild("main").Frame
local part = game.Workspace.click.ClickDetector

part.MouseClick:Connect(function()
	gui.Visible = true
end)
if part.MouseClick and Owns.Value == true
then 
	print("Working")
	gui.Visible = false
	Fram.Visible = true
end

Try this

local playergui = game.Players.LocalPlayer.PlayerGui
local gui = playergui:WaitForChild("buy")
local guiFrame = gui.Frame
local Owns = gui.Frame.Owns
local Fram = playergui:WaitForChild("main").Frame

part.MouseClick:Connect(function()
    gui.Visible = true
    if Owns.Value == true then
        Farm.Visible = true
        gui.Visible = false
    end
end)

Thats actually in another script here:

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local EP = player:FindFirstChild("leaderstats1")
		local points = EP:FindFirstChild("ElitePoints")
		local Owns = script.Parent.Parent.Owns
		if points ~= nil then
			points.Value = points.Value + 90
	    Owns.Value = true
		end
end)

This is your if statement then, you need to check to see if the owns value is true repeatedly. You only check it once and right when the player joins in the game.

I believe if part.MouseClick won’t work. It needs to be connected with a function.

The Owns.Value is set to true till the player leaves like how I stated above.

no you only check the value when the player first comes in, is the value true when the player first joins? Or only when they click the button?

Its set to true once they click the TextButton.

nvm, its a frame. Sorry for that.

Yea with this script MouseClick is not working

local playergui = game.Players.LocalPlayer.PlayerGui
local gui = playergui:WaitForChild("buy")
local guiFrame = gui.Frame
local Owns = gui.Frame.Owns
local Fram = playergui:WaitForChild("main").Frame
local part = workspace.click.ClickDetectorart.MouseClick:Connect(function()
    if Owns.Value == false then
	    guiFrame.Visible = true
    else 
        Fram.Visible = true
        guiFrame.Visible = false
    end
end)

I believe this will have the effect you are looking for.

local playergui = game.Players.LocalPlayer.PlayerGui
local gui = playergui:WaitForChild("buy")
local guiFrame = gui.Frame
local Owns = gui.Frame.Owns
local Fram = playergui:WaitForChild("main").Frame

part.MouseClick:Connect(function()
    gui.Visible = true
    if Owns.Value == true then
        Farm.Visible = true
        gui.Visible = false
    end
end) 

The issue you had was with the

if part.MouseClick then

You need to connect it to a function

part.MouseClick:Connect(function() 
2 Likes

Worked exactly the way I needed thanks a lot!

Ok so first it should be in a server script. The Click detector has a parameter for a player object value.

local part = game.Workspace.click.ClickDetector
part.MouseClick:Connect(function(Player)
    local playergui = Player.PlayerGui
    local gui = playergui:WaitForChild("buy")
    local guiFrame = gui.Frame
    local Owns = gui.Frame.Owns
    local Fram = playergui:WaitForChild("main").Frame
    gui.Visible = true
-- Bla bla bla
end)

I’m pretty sure that would fix the problem but then again, I did skim this post.