Updating the PlayerServer Script

The PlayerServer script will need to be updated so that it can hide the UI for the player if they are ready to be spawned in or joined late in the game.

Update OnPlayerJoined Function

Update the OnPlayerJoined function so that after a 1 second delay, it hides the UI for the player by broadcasting to them.

local function OnPlayerJoined(player)
	if spawnPointPosition ~= nil then
		player:SetWorldPosition(spawnPointPosition)
		player:SetWorldRotation(spawnPointRotation)

		Task.Wait(1)
		Events.BroadcastToPlayer(player, "HideUI")
	else
		player:Despawn()
	end
endCode language: Lua (lua)

Update SpawnPlayers Function

The SpawnPlayers function will also wait 1 second and then broadcast to all the players in the game so the UI is turned off.

local function SpawnPlayers(position, rotation)
	spawnPointPosition = position + (Vector3.UP * 150)
	spawnPointRotation = rotation

	Task.Wait(1)
	Events.BroadcastToAllPlayers("HideUI")

	for _, player in ipairs(Game.GetPlayers()) do
		player:Spawn({
	
			position = spawnPointPosition,
			rotation = rotation

		})
	end
endCode language: Lua (lua)

The PlayerServer Script

local spawnPointPosition = nil
local spawnPointRotation = nil

local function ActionPressed(player, action)
	if(action == "Toggle Fly Mode") then
		if(player.isFlying) then
			player:ActivateWalking()
		else
			player:ActivateFlying()
		end
	end
end

local function OnPlayerJoined(player)
	if spawnPointPosition ~= nil then
		player:SetWorldPosition(spawnPointPosition)
		player:SetWorldRotation(spawnPointRotation)

		Task.Wait(1)
		Events.BroadcastToPlayer(player, "HideUI")
	else
		player:Despawn()
	end
end

local function SpawnPlayers(position, rotation)
	spawnPointPosition = position + (Vector3.UP * 150)
	spawnPointRotation = rotation

	Task.Wait(1)
	Events.BroadcastToAllPlayers("HideUI")

	for _, player in ipairs(Game.GetPlayers()) do
		player:Spawn({
	
			position = spawnPointPosition,
			rotation = rotation

		})
	end
end

Input.actionPressedEvent:Connect(ActionPressed)
Events.Connect("SpawnPlayers", SpawnPlayers)
Game.playerJoinedEvent:Connect(OnPlayerJoined)Code language: Lua (lua)

Test the game

Test the game to make sure the progress UI is updated and then hidden when the nav mesh has been generated. Make sure to test in multiplayer preview mode as well.

Scroll to Top