Head is not a valid member of model

I’ve been trying to make this gun for an hour and I’ve been doing pretty good, but I’ve run into a problem when loading in. I’ve tried looking for the character through WaitForChild and FindFirstChild, I’ve spoken with friends, but I keep getting the same result.

local player = game:GetService("Players").LocalPlayer
local char = player.Character
if not char or not char.Parent then
	char = player.CharacterAdded:Wait()
endlocal mouse = player:GetMouse()

local ori = char.Head.Position
local dir = mouse.Hit.p

Each time, it results in saying the head is not a valid member or a silent error where it just doesn’t work.

2 Likes

Its because the Head isn’t in the Characters model yet
Use

local Head= char:WaitForChild("Head")
local ori = Head.Position

Tell me if this works!

Try this and make sure it is a Local Script

local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

if char then
	local head = char:WaitForChild("Head")
	local mouse = plr:GetMouse()

	local ori = head.Position
	local dir = mouse.Hit.p
end

I’ve actually tried that. It gave me a silent error. And if it didn’t, it couldn’t find the position and said it was indexing a nil value.

Still saying the same thing, even for FindFirstChild

Could you send the place you are testing this code in?

im assuming this is in a local script. Can you send the error message when you try the code?

https://gyazo.com/3208702bba24d0b4223c4d116902608c
This is one of the two errors.

I assume if you use WaitForChild it doesnt print anything out and does a silent error?

Yeah. It is honestly confusing me.

What is happening as of now is the script is not finding the Head model. Hence it gives the errror “attempt to index nil with position” as head is nil. Having a waitforchild simply waits the current script until the object is found but since it is not being found it is holding the script infnitely. I recommend looking in the players model in workspace and seeing if you are finding the head in the player model.

The following code should work

local character = (player.Character or player.CharacterAdded:Wait())
local head = character:WaitForChild("Head")

local mouse = player:GetMouse()