Remove Player Flying

Early on in the course, you added flying so that you could look at the map when writing the generation algorithm. Now, this should be removed otherwise players will be able to fly around.

In case you need to go back to flying for testing, you can comment out a single line to disable it for the game by commenting out the actionPressedEvent line. This means that when the toggle fly action is triggered, nothing will happen. You still have all the code there for when you do want to turn it back on.

--Input.actionPressedEvent:Connect(ActionPressed)Code language: CSS (css)

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 OnPlayerDied(player)
	Task.Wait(1)

	player:Spawn({
	
		position = spawnPointPosition,
		rotation = spawnPointRotation

	})
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

	player.diedEvent:Connect(OnPlayerDied)
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)
Scroll to Top