Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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

0
I tested the spawning 100% wont work BelgiumStorage 3 — 6y
0
Sorry for long wait, I've edited. TheDeadlyPanther 2460 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago

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")

Answer this question