Humanoid is not valid member of Model

For some unknown reason, when I attempt to change the Humanoid’s WalkSpeed, it returns with an error, “Humanoid is not a valid member of Model”. I do not understand why this is happening, because I have tested this code on different games and it works on that. I have read the code word-for-word and I cannot find the issue. I have also used the search tool and didn’t find any solutions.

(by the way, this is a LocalScript in StarterGui)

local StartPos = game.Workspace.Start.CFrame
local EndPos = game.Workspace.End.CFrame
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

while true do
	print("Hi") -- this is a statement to check if it works, which it does
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = StartPos
	player.Character.Humanoid.WalkSpeed = 0
	local TweenService = game:GetService("TweenService")
	local CameraTweenInfo = TweenInfo.new(
		5,
		Enum.EasingStyle.Quint,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
	)
	local CameraTween = TweenService:Create(Camera.CFrame, CameraTweenInfo, EndPos)
	CameraTween:Play()
	wait(5)
	local CameraTween2 = TweenService:Create(Camera.CFrame, CameraTweenInfo, StartPos)
	CameraTween2:Play()
	wait(5)
end
8 Likes

You need to wait for the humanoid and character to load in properly, in the loop do this:

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.WalkSpeed = 0
10 Likes

The humanoid is simply not in the model you are looking for.
This is probably because the player has yet to load in properly. I’d recomend first checking to see if there is a character then using :FindFirstChild(“Humanoid”) to check if the humanoid is there.

2 Likes