Hi, I have resently been trying to advance my skills a little bit. I was trying to make a UI that is visible to two players and only those 2 players. I have been experimenting with the .onClientEvent and then try to make it work for 2 player. But now I am a bit stuck on how to go now. This is my code:
Code:
-- Variables
local Player1 = nil
local Player2 = nil
local Storage = game.ServerInstanceStorage
local Event = Storage.Events.OpenTradeUI
-- Code
Event.OnClientEvent:Connect(function(plr1, plr2)
Player1 = plr1
Player2 = plr2
end)
I would send two remote events on the server to the clients that should see the gui.
Server:
-- Variables
local Player1 = nil
local Player2 = nil
local Storage = game.ServerInstanceStorage
local Event = Storage.Events.OpenTradeUI
-- Once you know which to players should see the gui:
Event:FireClient(Player1)
Event:FireClient(Player2)
Client:
Event.OnClientEvent:Connect(function() --When client recieves event, it makes the gui visible
GuiToMakeVisible.Visible = true
end)
The two guis will be different objects, so if one player changes the text for example, the other client won’t see it. To solve this, you need to send a remote event to the server and then the server sends a remote event to the other client so he changes the text.
I recommend you to learn more about client and server scripting.