How to make it, so button closes the GUI?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make the button close
  2. What is the issue? Include screenshots / videos if possible!
    Clicking Close Gui does nothing.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried rewriting the script, and looking for solutions on devforum.

local player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if player then
	wait(0.50)
	player.PlayerGui.ScreenGui.Frame.Visible = true
		script.Parent.Text = "Close Warning GUI"
	else
		player.PlayerGui.ScreenGui.Frame.Visible = true
		wait(0.5)
	player.PlayerGui.ScreenGui.Frame.Visible = false
		script.Parent.Text = "Open Warning GUI"
	end
	end)

Localscript ^

ServerScript:

wait(5)
print("Connected")
for i, player in ipairs(game.Players:GetPlayers()) do
	if player:GetRankInGroup(5251XXX) == 9 or 10 or 12 or 13 or 14 or 15 or 16 or 17 or 255 then
	player.PlayerGui.Warn.TextButton.Visible = true
	print(player.PlayerGui)
	end
	end

We’re focusing on the localscript, not the ServerScript.

3 Likes
local player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    print("Button pressed")
	if player then
        print("Showing GUI")
	    wait(0.50)
	    player.PlayerGui.ScreenGui.Frame.Visible = true
		script.Parent.Text = "Close Warning GUI"
	else
        print("Hiding Gui")
		player.PlayerGui.ScreenGui.Frame.Visible = true
		wait(0.5)
	    player.PlayerGui.ScreenGui.Frame.Visible = false
		script.Parent.Text = "Open Warning GUI"
	end
end)

Try this and see what prints?

image

Changes the textbox text, but it keeps printing out the same thing over and over upon firing mousebutton1click.

Try using this code that i have edited from the code u have in the local script

local player = game.Players.LocalPlayer
local state = false -- the gui is closed if its false

script.Parent.MouseButton1Click:Connect(function()
	if not state then
		wait(0.50)
		player.PlayerGui.ScreenGui.Frame.Visible = true
		script.Parent.Text = "Close Warning GUI"
		state = true
	else
		player.PlayerGui.ScreenGui.Frame.Visible = false
		script.Parent.Text = "Open Warning GUI"
		state = false
	end
end)

Hope its helpful :slight_smile:

im just trying to figure why your checking if player exists as the what I am to assume is open as it sets visible to true.

the thing is that itll only ever clos the gui if the player manages to click it while not existing, which would make it not exist so no script

If the player exist, then execute the rest of the code, otherwise pause code.

well if the player doesnt exist than there wouldnt be a script or a gui to click they wouldve left or been kicked

I proved your point wrong?

and how does showing me the thing that will only happen if there is a player proving me wrong?. also im not trying to sound mean im just tired.

Upon the player existing:


And if player does exist, and player fired MouseButton1Click on the GUI, then it’ll open:
image

Problem: You CAN’T change guis with player.Playergui. Instead of typing player.PlayerGui type:

script.Parent.Frame.Visible = true

script.Parent.Frame.Visible = false

And put the local script inside the screen gui

image

No, put the local script inside warn screen gui not button

image

If I do that, it won’t work for the button when firing MouseButton1Click:Connect(function()

we can type that in my opinion cuz i have tested with that.

well actually you can change gues with player gui, player gui is what holds screen gui it has nonething to do with changing stuff, you could test it with

local playerGui = game:GetService("Players").LocalPlayer.PlayerGui

local gui = script.Parent -- place this local script in a screen gui

wait(10)
gui.TextLabel.Text = "this is one method" -- have the gui have a textlabel in it
wait(10)
playerGui.ScreenGui.TextLabel.Text = "This also works"

but besides that what is the preset text for the textbutton?

image
image
image
image

so, yea when the player leaves and rejoins the preset text is open warning gui