✓ 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")
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
my gui is located over here: game.Players.LocalPlayer.PlayerGui.MediterraneanAvenue.StartUp
is it okay if I just put local ScreenGui = game.Players.LocalPlayer.PlayerGui.MediterraneanAvenue.StartUp ?
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?
no my gui is a frame named startup under mediterraneanAvenue. MediterraneanAvenue has other frames I dont want to delete
local ScreenGui = v:FindFirstChild("PlayerGui"):WaitForChild("ScreenGui") <-- Replace ScreenGui with the Gui you want to destroy for all players
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?
no, startup is a frame inside Mediterranean Avenue. Start up is being destroyed
no, startup is a frame inside Mediterranean Avenue. Start up is being destroyed
local ScreenGui = v:FindFirstChild("PlayerGui"):WaitForChild("MediterraneanAvenue"):WaitForChild("StartUp") --is this correct?
MediterraneanAvenue is a screen gui. The mediterraneanAvenue I changed parents for was actually a tool, so dont confuse with it. Pleasseeeee help me!
Actually I ot it bro