I am currently making a lobby system where upon the first player entering, they can set various things like whether other player can enter and when the game starts. I am having issues making the UI for the settings of the lobby appear. (Note: I only want the settings UI to appear for the first person to enter the lobby.)
Here is my current code:
local sgui = script.Parent.SurfaceGui
local owner = sgui.Owner
local requirement = sgui.Requirement
local status = sgui.Status
local publicity = sgui.Publicity
local teleDest = game.Workspace.TeleDestination1
local menu = game.StarterGui.LobbyMaking1
local publicityNum = 1
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not (player and player.Character) then return end
if #plyrs == 0 then
owner.Text = player.Name .."'s Lobby"
table.insert(plyrs, player)
print(plyrs)
print(#plyrs)
status.Text = "Players: " .. #plyrs
publicityNum = 3
publicity.Text = "Private"
player.Character:FindFirstChild("HumanoidRootPart").CFrame = teleDest.CFrame + Vector3.new(0,5,0)
for _, child in ipairs(menu:GetChildren()) do
child.Visible = true
end
else
if publicityNum == 3 then return end
local idx = table.find(plyrs, player)
if idx == nil then
table.insert(plyrs, player)
print(plyrs)
print(#plyrs)
status.Text = "Players: " .. #plyrs
player.Character:FindFirstChild("HumanoidRootPart").CFrame = teleDest.CFrame + Vector3.new(0,5,0)
end
end
end)
Things from the StarterGui get cloned to each player’s PlayerGui, so if you make any changes in there they won’t be reflected in realtime. You can use the player variable you already have to get the UI:
local sgui = script.Parent.SurfaceGui
local owner = sgui.Owner
local requirement = sgui.Requirement
local status = sgui.Status
local publicity = sgui.Publicity
local teleDest = game.Workspace.TeleDestination1
local publicityNum = 1
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not (player and player.Character) then return end
local PG = player.PlayerGui
local menu = PG:WaitForChild("LobbyMaking1")
if #plyrs == 0 then
owner.Text = player.Name .."'s Lobby"
table.insert(plyrs, player)
print(plyrs)
print(#plyrs)
status.Text = "Players: " .. #plyrs
publicityNum = 3
publicity.Text = "Private"
player.Character:FindFirstChild("HumanoidRootPart").CFrame = teleDest.CFrame + Vector3.new(0,5,0)
for _, child in ipairs(menu:GetChildren()) do
child.Visible = true
end
else
if publicityNum == 3 then return end
local idx = table.find(plyrs, player)
if idx == nil then
table.insert(plyrs, player)
print(plyrs)
print(#plyrs)
status.Text = "Players: " .. #plyrs
player.Character:FindFirstChild("HumanoidRootPart").CFrame = teleDest.CFrame + Vector3.new(0,5,0)
end
end
end)