Attempt to index nil with 'FindFirstChild'

I am making custom character sounds for my game with material walksounds and i got this error on my script. I implemented this script in Roblox’s RbxCharacterSounds script. When ever I run the game i get this error. Please ask questions if your confused what im saying. Thankyou all!

local char = script.Parent.Parent.Character
local Humanoid = char:FindFirstChild("Humanoid")
local walkset = "0"

if Humanoid then
	if Humanoid.FloorMaterial == Enum.Material.Grass or Humanoid.FloorMaterial == Enum.Material.LeafyGrass then
		walkset = "rbxassetid://"Hiddenforcoppyingpurpose"
	end


if Humanoid.FloorMaterial == Enum.Material.Grass or Humanoid.FloorMaterial == Enum.Material.LeafyGrass then
	walkset = "rbxassetid://Hiddenforcoppyingpurpose"

	end
	
	
	
end

Running = {
		SoundId = walkset,
		Looped = true,
		Pitch = 1.2,

Where is your script parented too? If it is in the character then change the first line to
local char = script.Parent

I think you were originally trying to get the player then the character, but the parent of a character is not a player

It is parented to StarterPlayerScripts

i will send a screen shot if needed

If patented to starter player scripts you will need to do this
local player = game:GetService(“Players”).LocalPlayer local char = player.Character

Sorry if it’s formatted weird I’m on my phone

I would suggest putting this script in starter character because in starter player the script will only run once when the player joins the game. Putting it in starter character will have it run each time a character is loaded.

By deafault roblox has it starter player i think

Am able to do LocalPlayer.Character? it still doesnt seem to work

If you have the script in starter player then you would have to use the character added event to get the character each time it loads in.
https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAdded

1 Like

Place the script is StarterCharacterScripts, and try:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() 
1 Like

This stopped the error from occuring but the Humanoid doesnt seem to be founded by the script. The thing is that the humanoid is indeed present in the character

Just use WaitForChild("Humanoid") on the global scope.

1 Like