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?
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.