"Argument 1 missing or nil" in first line of a function

Hello. I’ve having some issues with this function. For some reason, the first line of it is erroring, and I can’t figure out why.

function SoundService:ActivateSound(Phase)
--Below Line Errors
local SoundSearch = LocalPlayer.Character:FindFirstChild("Head"):FindFirstChild(Phase) --Error here
if SoundSearch and SoundSearch:IsA("Sound") and SoundSearch.SoundId ~= "rbxassetid://0" then
	if SoundSearch.IsLoaded then
	SoundSearch:Stop() --Reset
	SoundSearch:Play()
	else
	Tool.ErrorLogger:FireClient(LocalPlayer,"[Green's Weapon System]: Non-Fatal Error - Code x0004-2")					
	end
else
Tool.ErrorLogger:FireClient(LocalPlayer,"[Green's Weapon System]: Non-Fatal Error - Code x0004-1")
end
end

This is being run in a serverside script. The “local player” is defined here:

	script.Parent.GunEquip.OnServerEvent:Connect(function(player,EquipType)
			GunEquipted = EquipType
			LocalPlayer = player
			AnimationService.PreloadAnimation(Tool.Parent:FindFirstChildOfClass("Humanoid"))
			SoundService:GenerateRemotePresets()
			if EquipType then
				SoundService:LoopSound("Idle")
				AnimationService:LaunchAnimationByMethod("EquipGun",EquipType)
			else
				SoundService:BreakLoop("Idle")
				AnimationService:Stop()
			end		
		end)
  14:47:52.943  Argument 1 missing or nil  -  Server - CoreHandler:162

I really don’t see what the issue is, and have been stuck on this for ~15 minutes. Anyone know a fix?

What is the Phase variable defined as in your parameter?

It’s defined as “Fire” (A String Value)

Try and check if the Value you’re looking for is the “Fire” string

function SoundService:ActivateSound(Phase)
    print(Phase)
--Below Line Errors
if LocalPlayer.Character.Head:FindFirstChild(Phase) then
    local SoundSearch = LocalPlayer.Character:FindFirstChild("Head"):FindFirstChild(Phase) --Error here
    if SoundSearch and SoundSearch:IsA("Sound") and SoundSearch.SoundId ~= "rbxassetid://0" then
	    if SoundSearch.IsLoaded then
            SoundSearch:Stop()
            SoundSearch:Play()
        else
	        Tool.ErrorLogger:FireClient(LocalPlayer,"[Green's Weapon System]: Non-Fatal Error - Code x0004-2")					
	    end
    else
        Tool.ErrorLogger:FireClient(LocalPlayer,"[Green's Weapon System]: Non-Fatal Error - Code x0004-1")
    end
end
end

@Jackscarlett And I just restarted studio, and magically the code is working flawlessly now. No idea why it wasen’t before, I didn’t change anything. Sorry to have been of bother

That’s weird, well glad you got it fixed then :thinking: