How do I show a GUI To a table

Hello, I am making a Story game, The lobby is being built, but to save time, I decided to script it, I have no problems, until it dawned on me, that I cannot think of a way to show a BlackGui To a Table, when teleporting, the GUI Comes down, and it needs to be cloned, since it’s in ServerStorage, it needs to be put into the player’s who are in the Bus Table Player Guis’ However, I don’t want to show it to just one person, or Everyone in the game, just the players who are in the Bus Table…
Here is my script, the script needs to go where it says --This is where the black gui needs to come down

Here is my main script, I have a few others, for the timer, etc:

--Variables

local TeleportService = game:GetService('TeleportService')
local PlayersInBus = game.Workspace.HitBox1.PlayersInBus
local BusTable = {}
local Bus1 = game.Workspace.Bus1
local teleporting = false

--Call The TeleportService ReserveServer Function
 
code = TeleportService:ReserveServer(56314517)

--Functions

function OnTouched(hit)
	local Debounce = false
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if hit.Parent:FindFirstChild('Humanoid') and teleporting == false then
        local findPlayer = table.find(BusTable, player) 
        if findPlayer == nil then
			local hum = player.Character.Humanoid
			for _, seat in pairs(Bus1.Seats:GetChildren()) do
				if seat.Occupant == nil then
					hum.WalkSpeed = 0
					hum.JumpPower = 0
					PlayersInBus.Value = PlayersInBus.Value + 1
					player.Character.HumanoidRootPart.CFrame = seat.CFrame
					game.ReplicatedStorage.ShowUI1:FireClient(player)
					table.insert(BusTable, player)
			    	break
				end	
			end
		end
	end
end
	
	
function RemovePlayer(Player)
	Player:LoadCharacter()
	local PlayerToRemove = table.find(BusTable, Player)
	PlayersInBus.Value = PlayersInBus.Value - 1
	table.remove(BusTable, PlayerToRemove)
end

script.Parent.Touched:Connect(OnTouched)
game.ReplicatedStorage.RemovePlayer1.OnServerEvent:Connect(RemovePlayer)

function PlayerLeft(Player)
	local GetPlayer = table.find(BusTable, Player)
	if GetPlayer ~= nil then
		table.remove(BusTable, GetPlayer)
		PlayersInBus.Value = PlayersInBus.Value - 1
		print('Removed: '..Player.Name..' From the BusTable! They have left..')
	end
end

game.Players.PlayerRemoving:Connect(PlayerLeft)



--loops

while true do
	wait()
	if game.Workspace.HitBox1.Teleporting.Value == true then
		teleporting = true
		 --This is where the black gui needs to come down
		TeleportService:TeleportToPrivateServer(56314517, code, BusTable)
		wait(10)
		teleporting = false
	end
end

The local script in the Gui is this:

script.Parent.Frame.Position = UDim2.new(0,0,-1,0)
script.Parent.Frame:TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Quad,1)

If you know how to do that, Please let me know!
Thank you!

1 Like

if you wish for all players in the BusTable to get the GUI you can iterate through the BusTable and clone the GUI to their PlayerGui (player.PlayerGui)

for _, player in ipairs(BusTable) do
local newGui = GUI:Clone()
newGui.Parent = player.PlayerGui
end

I’d recommend waiting a second or two after cloning so that they player’s can see the GUI before teleporting
@Esythia

2 Likes

Can you show an example?..

Ill try that out…

When you teleport the players, you will want to fire a remote event from the server to the client, telling the client to show the GUI. When the client receives this signal from the server you need to tween the GUI down.

Something like this
Server:

local remoteEvent = game.Lighting.Remotes.Teleport

local function teleport(playerTable)
	for _, player in ipairs(playerTable) do
		local plr = game.Players:FindFirstChild(player)
		if (plr) then
			remoteEvent:FireClient(plr)
		end
	end
end

Client:

local remoteEvent = game.Lighting.Remotes.Teleport

local function tween()
	script.Parent.Frame.Position = UDim2.new(0,0,-1,0)
	script.Parent.Frame:TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Quad,1)
end

remoteEvent.OnClientEvent:Connect(tween)

Disclaimer: This code is untested and may have syntax / logic errors that I have overlooked.

You know that the issue is about the Table,
so let’s document it if you lacks knowledge in how to manipulate the contents.

You can notice that one of the useage example of the Tables have the following :

local testArray = {"A string", 3.14159, workspace.Part, "New string"}
 
-- Loop using "ipairs()"
for index, value in ipairs(testArray) do
	print(index, value)
end

if you know about :GetChildren(), then you’ll realize that a Table version to get childrens exist !

So, you just have to edit it and selecting the desired table :

for key, value in pairs(BusTable) do
	print(value.Name)
end

Now that you successfully selected all the players, you can send informations to all of them with
:FireClient(player, argument), which is a RemoteEvent activation.

for key, value in pairs(BusTable) do
	Instance:FireClient(value, "Exit")
end

However, this is the server attempting to call the Player,
So you also have to do a Localscript that respond to the server’s call !

Wiki Example :

local function LeaveBus()
	welcomeMessage.Visible = true
	wait(3)
	welcomeMessage.Visible = false
end
 
Event.OnClientEvent:Connect(LeaveBus)

You should note that, in order to etablish a connection between the server and the client,
you should have a “RemoteEvent” that is being connected by both side

NOTE : The post above me shows a example of variable of where a remoteevent object can be potentially placed at, people usually use ReplicatedStorage and just select it like so :

Event = game.ReplicatedStorage:WaitForChild("Event") -- name of the object

1 Like

Thank you. It works…