How can i delete the player and change the camera to something else?

For simplicity, i just want to delete/hide the player character and set the camera to another part in workspace, as i’m going to control that part instead.
How can i do it?
Note that the script below is in StarterPlayerScripts.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)

		for _, part in ipairs(char:GetChildren()) do
			if part:IsA("BasePart") then
				part.Transparency = 1
				part.CanCollide = false
			elseif part:IsA("Humanoid") then
				part:ChangeState(Enum.HumanoidStateType.Physics)
			end
		end

		local camera = workspace.CurrentCamera
		local ship = workspace.GameObjects:WaitForChild("Ship")
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CameraSubject = ship
		camera.CFrame = ship.CFrame
	end)
end)
1 Like

Does this code right now not work? Also if you want to be able to use the players character again, then you might want to anchor the parts in it or else they are gonna fall though the floor and get deleted.

There’s no gravity. The code doesn’t work, the player just spawns in like this:
image
However, i’ll keep your suggestion in mind.

What I did to hide the character was get PlayerControls and disable the controls from there, so the character no longer moves. Then I had a for loop which goes through all the limbs/accessories in the character and sets their transparency.

local playerControls = require(Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
playerControls:Disable()

for _, child in pairs(character:GetChildren()) do
    if child:IsA("BasePart") then
        child.Transparency = 1
    elseif child:IsA("Accessory") then
        child.Handle.Transparency = 1
    end
end

Then for the camera, I set it to Scriptable and set the CFrame to an attachment:

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = attachment.WorldCFrame
1 Like

PlayerAdded will not fire from a localscript in starterplayerscripts for when the local player joins, since they are already in the game. You could try moving all the code in the PlayerAdded outside the event listener and see if that makes a difference.

1 Like


Works now! Thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.