We use cookies on this site to enhance your user experience

PlayerShipHandler

PlayerShipHandler

Sep 04 2018, 1:39 PM PST

--This script handles ship behavior on the server-side of the game

-- Called when the character is added
local function onCharacterAdded(character)
	local rootPart = character:WaitForChild("HumanoidRootPart")

	-- Wait until rootPart is part of the workspace		
	while not rootPart:IsDescendantOf(workspace) do
		wait()
	end
	-- Gives control of the ship to the player
		rootPart:SetNetworkOwner(game.Players:GetPlayerFromCharacter(character))
end

-- Called when a player is added to the game
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

-- Connect onPlayerAdded() to the PlayerAdded event.
game.Players.PlayerAdded:Connect(onPlayerAdded)