Localscript can't destroy or change things after character removal

  1. What do you want to achieve?
    I want to change player camera mode and remove some local models after CharacterRemoving function.

  2. What is the issue?
    I couldn’t find any solutions.

  3. What solutions have you tried so far?
    I don’t know what to do so i couldn’t tried anything. Also I couldn’t find a solution on Creator Forum.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local FigureHead = ReplicatedStorage:WaitForChild("Figure Morph Assets"):WaitForChild("Head"):Clone()
local FigureArms = ReplicatedStorage:WaitForChild("Figure Morph Assets"):WaitForChild("Arms"):Clone()

for _, model in ipairs({FigureHead, FigureArms}) do
	for _, obj in ipairs(model:GetDescendants()) do
		if obj:IsA("BasePart") then
			obj.Anchored = true
			obj.CanCollide = false
		end
	end
	model.Parent = workspace
end

RunService.RenderStepped:Connect(function()
	FigureHead:SetPrimaryPartCFrame(camera.CFrame * CFrame.new(0, 0.075, 0.1))
	FigureArms:SetPrimaryPartCFrame(camera.CFrame * CFrame.new(0, -2, 0))
end)

player.CameraMode = Enum.CameraMode.LockFirstPerson

-----------------------------------------------------

player.CharacterRemoving:Connect(function(character)
	player.CameraMode = Enum.CameraMode.Classic
	FigureArms:Destroy()
	FigureHead:Destroy()
	print("Character Removed: " .. character.Name)
end)

The main code of topic is bottom of the script after “-----------------------------------------------------”.

That’s the code. After CharacterRemoving function I can’t destroy local models or change local player’s settings. Because character is already removed and it’s too late.

Are you using this in StarterCharacterScripts? If so I suggest you switch over to StarterPlayerScripts.

No I’m using StarterPlayerScripts. I’m working on a morph script. The localscript is placing to StarterPlayerScripts when morphing.