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

Humanoid is not a valid member of model?

Asked by 3 years ago
Edited 3 years ago

Hey I am currently making a first person script and I am having a problem, the problem is is that it says "18:18:31.139 - Humanoid is not a valid member of Model", I honestly dont know what is happening. Please help.

local player = game.Players.LocalPlayer
local char = player.Character
local hum = char.Humanoid
local cam = workspace.CurrentCamera

cam.FieldOfView = 100
hum.CameraOffset = Vector3.new(0,0,-1)

for childIndex, child in pairs(char:GetChildren()) do
    if child:IsA("BasePart") and child.Name ~= "Head" then
        child:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
            child.LocalTransparencyModifier = child.Transparency
        end)
        child.LocalTransparencyModifier = child.Transparency
    end
end

Error: 18:18:31.139 - Humanoid is not a valid member of Model

1 answer

Log in to vote
2
Answered by
zane21225 243 Moderation Voter
3 years ago
Edited 2 years ago

The issue here is that you are getting the Humanoid before it is loaded into the game.

A better solution would be:

-- Variables:
local Camera = workspace.CurrentCamera

local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Hum = Char:WaitForChild('Humanoid')
Ad

Answer this question