I would like to know if I can make a gui open only for 2 people

So I would like to know if I can make a GUI open only for 2 people because I’m making a trading system and I would like to know how to make the GUI only open for 2 people so they can trade

1 Like

Get the server to fire a remote event to the players and have a local script connect to it and open the guis.

2 Likes

how do i do the local script par i understand ho to fire the event but not the second part

Create a local script somewhere where it can run and connect to the event:

-- example
RemoteEvent.OnClientEvent:Connect(function()
   TradeGui.Visible = true -- make the gui visible
end)

but how will it ONLY open for 2 players

LocalScripts only operate for you. They don’t affect anyone else. Which is why I said fire the event to both of the players so their scripts can run.

-- server script
RemoteEvent:FireClient(Player1)
RemoteEvent:FireClient(Player2)

but the players in my game are not going to be name player 1 and 2

I know that, it was an example. You don’t send their names you send their Instance.

RemoteEvent.OnServerEvent:Connect(function(player) -- roblox passes the player who fired the event
   RemoteEvent2:FireClient(player) -- fire the remote for the player
end)

No when he said player1 he meant that’s a variable that is referencing the player object: game.Players.WhateverTheNameOfThePlayerIs

For example what you can do is on the server script

local Bob = game.Players:FindFirstChild("Bob");
RemoteEvent:FireClient(Bob, "OpenGui")

Which would find the player named Bob and send “OpenGui”. From there you could set up on the local script

RemoteEvent.OnClientEvent:Connect(function (Event)
      if (Event == "OpenGui") then
        -- code to open gui
      end
end)

Read the pages that @HugeCoolboy2007 linked
On mobile so sorry for weird formatting

You would replace those with something such as:
game.Players.playerUsername_123

I am pretty sure it’s if Event == “OpenGui” then. I think that syntax is in JavaScript.

You can use that in Luau as well.

2 Likes

You would use a remote event and fire it to a client.

If you don’t know how to do this follow these steps:

  1. Create a RemoteEvent inside ReplicatedStorage.
  2. Create a LocalScript.
  3. Put this inside your LocalScript:
   local remote = game.ReplicatedStorage.RemoteEvent
   local plr = game.Players.LocalPlayer
   
   remote.OnClientEvent:Connect(function(gui)
       local gui = plr.PlayerGui:FindFirstChild(gui)
       
       if gui then
          -- do stuff
       end
   end)
  1. Parent your LocalScript to StarterPlayerScripts.
  2. Inside your script you’ll want to fire that remote like this:
local remote = game.ReplicatedStorage.RemoteEvent

remote:FireServer(game.Players.playerusername, 'guiname')

This will only work if your script that your using to fire the remote is a server script.

Nah you can if (condition) in Lua and Luau, and it’s a habit that has carried over from C# and JavaScript :wink: