Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do I make a cloned gui pop up for everyone in the game?

Asked by 1 year ago
Edited 1 year ago

My friends and I have been working on a Roblox Game.

This Roblox game is supposed to have lobbies in them using Guis. For those who do not know what a GUI lobby is, here is a quick example:

Basically, a Gui Lobby is when you click a "Create Lobby" button on your screen using a TextButton, which will clone a Gui that says the player's lobby title, and how many players the lobby has already.

This GUI will appear for everyone on the server, so when they click the "Open Lobbies" button, they will see that guy's lobby.

I wanted to make something similar by using RemoteEvents, a Script, and a LocalScript.

(Before you look at the Scripts below, please note that the RemoteEvent is located in the create lobby button, as well as the Script and the LocalScript).

This is my LocalScript (Inserted inside ScreenGui):

local event = script.Parent.CreateEvent

local plrName = game.Players.LocalPlayer.Name

script.Parent.MouseButton1Click:Connect(function()
    event:FireServer()
end)

This is my Server Script:

local event = script.Parent.CreateEvent

local rs = game:GetService("ReplicatedStorage")

local background = rs.PlayerLobby
local mainBackground = script.Parent.Parent.Parent.PlayerLobby

event.OnServerEvent:Connect(function(player)
    local guiClone = background:Clone()
    guiClone.Name = player.Name
    guiClone:WaitForChild("LobbyTitle").Text = player.Name .. "'s Lobby"
    script.Parent.Parent.LobbiesFrame.CanvasSize += UDim2.new(0, 0, 1, 0)
    guiClone.LobbySize.PlayersAmount.Value += 1
    guiClone.OwnerUsername.Value = player.Name
    guiClone.Parent = player.PlayerGui.LobbiesGui.Background.LobbiesFrame
    guiClone.Visible = true

    local inlobbyClone = mainBackground:Clone()
    inlobbyClone.Name = player.Name
    inlobbyClone.Parent = script.Parent.Parent.Parent
    local playerOnwner = Instance.new("StringValue")
    playerOnwner.Name = player.Name
    playerOnwner.Parent = inlobbyClone.LobbyOwner
    playerOnwner.Value = player.Name
    local newplayerToQue = Instance.new("StringValue")
    newplayerToQue.Name = player.Name
    newplayerToQue.Parent = inlobbyClone.QuePlayersNames
    newplayerToQue.Value = player.Name
end)

When I test the game, the lobby pops up for only me, but no one else in the server.

If anyone has an answer to this or anything, please let me know!

1 answer

Log in to vote
0
Answered by 1 year ago

Correct me if I'm wrong, but the reason I think the lobby pops up for only you is that you didn't use the :FireAllClients function. To do this, a local script has to call the server and the server has to call :FireAllClients since localscripts manage guis, which is what the clients only see.

Local script: (Same thing)

 local event = script.Parent.CreateEvent

 local plrName = game.Players.LocalPlayer.Name

 script.Parent.MouseButton1Click:Connect(function()
     event:FireServer()
 end)

Server script:

local event = script.Parent.CreateEvent

local rs = game:GetService("ReplicatedStorage")

event.OnServerEvent:Connect(function(player)
   event:FireAllClients(player)
end)

Gui creating script (Local script):

local event = script.Parent.CreateEvent

local rs = game:GetService("ReplicatedStorage")

local background = rs.PlayerLobby
local mainBackground = script.Parent.Parent.Parent.PlayerLobby

event.OnClientEvent:Connect(function(player)
    local guiClone = background:Clone()
    guiClone.Name = player.Name
    guiClone:WaitForChild("LobbyTitle").Text = player.Name .. "'s Lobby"
    script.Parent.Parent.LobbiesFrame.CanvasSize += UDim2.new(0, 0, 1, 0)
    guiClone.LobbySize.PlayersAmount.Value += 1
    guiClone.OwnerUsername.Value = player.Name
    guiClone.Parent = player.PlayerGui.LobbiesGui.Background.LobbiesFrame
    guiClone.Visible = true

    local inlobbyClone = mainBackground:Clone()
    inlobbyClone.Name = player.Name
    inlobbyClone.Parent = script.Parent.Parent.Parent
    local playerOnwner = Instance.new("StringValue")
    playerOnwner.Name = player.Name
    playerOnwner.Parent = inlobbyClone.LobbyOwner
    playerOnwner.Value = player.Name
    local newplayerToQue = Instance.new("StringValue")
    newplayerToQue.Name = player.Name
    newplayerToQue.Parent = inlobbyClone.QuePlayersNames
    newplayerToQue.Value = player.Name
end)
0
sadly, this dosn't work. I just tried this. (Sorry for the late response.) JackyW9cky 27 — 1y
Ad

Answer this question