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

How to set frame.visible = false for all players?

This is my current script to destroy the gui after a player clicks on it: (LocalScript- inside the Gui which I want to disappear after I click)

script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.Cash.Value >= 60 then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 60
		script.Parent.Parent:Destroy()
		MediterraneanAvenue.Parent = game.Players.LocalPlayer.Backpack

however, I want the gui gets destroyed only for the player who clicks it. I want the gui to be destroyed from all players, or set enabled = false for that sake.

How can I do this? With what code? can you please help me?

1 answer

✓ Accepted answer

I'm kind of confused by your question, I'm assuming your question is that all players will have the ScreenGui and when the button inside the ScreenGui is clicked it will destroy all ScreenGuis for all players in the game? If so, this is very simple to do with RemoteEvents.

First of all, put a RemoteEvent inside of ReplicatedStorage.

Second, place a Local Script inside of the button and put the following code inside of it:

script.Parent.MouseButton1Click:Connect(function()

	if player.leaderstats.Cash.Value >= 60 then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 60
		game.ReplicatedStorage.RemoteEvent:FireServer() 

		MediterraneanAvenue.Parent = game.Players.LocalPlayer.Backpack
	end
end)

Next you will need to put a Server Script inside of ServerScriptService and then put the following code inside of it:

local Players = game:GetService("Players")

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	
	for i,v in pairs(Players:GetChildren()) do
		local PutGuiNameHere = v:FindFirstChild("PlayerGui"):WaitForChild("PutGuiNameHere") -- Replace "PutGuiNameHere" with the Gui name that you want to destroy.
		PutGuiNameHere:Destroy()
		
	end
end)

Again, It was hard to understand what you were asking for and hopefully this is the answer you were looking for.

If this is not what you were asking for, just put a comment below and I'll try to help you.

11 comments

0

my gui is located over here: game.Players.LocalPlayer.PlayerGui.MediterraneanAvenue.StartUp

0

is it okay if I just put local ScreenGui = game.Players.LocalPlayer.PlayerGui.MediterraneanAvenue.StartUp ?

0

The Local ScreenGui is the Gui that is being destroyed. Is MediterraneanAvenue the Gui you want to destroy? If so, then yes, replace the Local ScreenGui to Local ScreenGui = v:FindFirstChild("PlayerGui"):WaitForChild("MediterraneanAvenue") Also I noticed that in your post you set the parent of MediterraneanAvenue to the player's Backpack, is it supposed to be in the backpack or the PlayerGui? 

0

no my gui is a frame named startup under mediterraneanAvenue. MediterraneanAvenue has other frames I dont want to delete

0

local ScreenGui = v:FindFirstChild("PlayerGui"):WaitForChild("ScreenGui") <-- Replace ScreenGui with the Gui you want to destroy for all players

0

I apologise if I don't quite understand your question. So is MediterraneanAvenue in the Gui that's being destroyed? Is that why you're changing it's parent?

0

no, startup is a frame inside Mediterranean Avenue. Start up is being destroyed

0

no, startup is a frame inside Mediterranean Avenue. Start up is being destroyed

0

local ScreenGui = v:FindFirstChild("PlayerGui"):WaitForChild("MediterraneanAvenue"):WaitForChild("StartUp") --is this correct?

0

MediterraneanAvenue is a screen gui. The mediterraneanAvenue I changed parents for was actually a tool, so dont confuse with it. Pleasseeeee help me!

0

Actually I ot it bro

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