how can I make a GUI visible and invisible with writing (open) and (close) in chat
and I also want JUST I can do this
like if anyone says open and it is not me I want gui to keep close not open
So, the thing is that every Gui instance in the StarterGui replicates to everyone’s PlayerGui, which resides on their client.
So, you will have to connect a server-side Chatted event with a RemoteEvent which should call FireAllClients from a server script with relevant parameters. Then on the client in a LocalScript (you can just parent it in the StarterGui) you need to connect a OnClientEvent to a function which changes the visibility of the Gui.
I make it a habit not to give full answers, but it’s not hard code, so here:
-- Server-side:
local RepStore = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local GuiVisibleEvent = RepStore:WaitForChild("GuiVisibleEvent") -- Create a RemoteEvent in ReplicatedStorage and name is 'GuiVisibleEvent'
Players.PlayerAdded:Connect(function(newPlayer)
if newPlayer.UserId == 664659259 then
newPlayer.Chatted:Connect(function(chat)
if chat == "(open)" then
GuiVisibleEvent:FireAllClients(true)
elseif chat == "(close)" then
GuiVisibleEvent:FireAllClients(false)
end
end)
end
end)
-- Client-side (LocalScript in StarterGui):
local RepStore = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local ParentFrameOfUI = PlayerGui:WaitForChild("ScreenGui"):WaitForChild("YOUR FRAME HERE") -- name of the UI frame you want invisible
local GuiVisibleEvent = RepStore:WaitForChild("GuiVisibleEvent")
GuiVisibleEvent.OnClientEvent:Connect(function(boolValue)
ParentFrameOfUI.Visible = boolValue
end)
This should do it for you! Beware, there may be minor typos so might not work and you have to write in the frame you want for the ParentFrameOfUI variable.
Sidenote: If StarterGui.ResetOnSpawn variable is true, people who respawn will see the Gui in its default visibility.
I am going to put gui in startergui or another place?
Startergui, put the localscript there too as GGGGG14 stated. (You can get away with putting it in playerscripts too)
But make sure to put the server script either in workspace or SSS.