I am trying to change a players model - I did some research into the matter and butchered a few different scripts together to match what I was trying to do. The main script works, I can control the new model as intended; the problem lies within the camera. It stays where the previous players model lies - as expected. The specific error occurs when I attempt to swap the cameras subject.
This is the main script, located in ServerScriptService
local RS = game:GetService("ReplicatedStorage")
local GMORPH = RS.Morphs:WaitForChild("GRUNT_MODEL")
local gruntMorphEvent = RS.Events:WaitForChild("GruntMorphEvent")
local newMorphCamEvent = RS.Events:WaitForChild("NewMorphCamEvent")
local function onGruntMorphFired(Player)
local char = Player.Character
local morph
morph = GMORPH:Clone()
morph.Name = Player.Character.Name
morph.Parent = workspace
Player.Character = morph
char:Destroy()
newMorphCamEvent:FireClient(Player, morph)
end
gruntMorphEvent.OnServerEvent:Connect(onGruntMorphFired)
and this is the camera script - located in StarterGui. This script has the error
local RS = game:GetService("ReplicatedStorage")
local newMorphCamEvent = RS.Events:WaitForChild("NewMorphCamEvent")
newMorphCamEvent.OnClientEvent:Connect(function(Player, morph)
wait(1)
-- error is here
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char.Humanoid
local humanoid = morph:WaitForChild("Humanoid")
workspace.CurrentCamera.CameraSubject = morph.Head
workspace.CurrentCamera.CameraType = Enum.CameraType.Follow
end)

1 comment
You are trying to get the character from the character. Try using game.Players.Player.Character instead, or use game.Workspace.Player as that is already the character.