Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[FE] Player:LoadCharacter() will not load the character in?

I am trying to reset my camera after an intro, but whenever I try to reset the camera I get the error "Humanoid is not a valid member of Model" obviously showing that the Character isn't spawning in. Any help?

Local Script

player = game.Players.LocalPlayer
game.ReplicatedStorage.FixCam:FireServer(player)
wait(.2)
game.Workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"

Script

event = game.ReplicatedStorage.FixCam

event.OnServerEvent:connect(function(player)
		player:LoadCharacter()
end)

2 answers

No, the character is spawning in.

If the character wasn't, the so called 'Model' wouldn't even exist. The problem here is that you trying to get the Humanoid before it has loaded.

A simple fix is to use player.Character:WaitForChild("Humanoid").

Edit: I just realised that if your ping is above 100ms, this code won't work. What you want to do is simply bind the CharacterAdded function to what you have already:

local player = game.Players.LocalPlayer -- use local to make defining variables more efficient
local event = game.ReplicatedStorage:WaitForChild("FixCam")
local camera = workspace.CurrentCamera -- workspace is already defined in Roblox Lua, so you might as well use it

player.CharacterAdded:Connect(function(character)
	camera.CameraSubject = character:WaitForChild("Humanoid")
end)
-- setup the listener before you do anything so this will be guaranteed to pick it up even if the character is loaded instantly

event:FireServer()
-- the server callback automatically adds the player it was recieved from to the arguments, so you don't need to provide it here

Hope I helped!

~TDP

2 comments

0

I tested the spawning 100% wont work

0

Sorry for long wait, I've edited.

game.Workspace can be replaced to just workspace the 'player' in FireServer(player) is not needed

Here's the answer: In the Server Script replace

event = game.ReplicatedStorage.FixCam

by

event = game.ReplicatedStorage:WaitForChild("FixCam")

This discussion is preserved as it was. New answers, comments, and votes are closed.