Trouble With Animating Player Within a Function

I have a function that animates the player:

local function useGrillToCook(plr,grill)
	local character = plr.Character
	if not character or not character.Parent then
		character = plr.CharacterAdded:Wait()
	end
	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:WaitForChild("Animator")
	local useGrill = Instance.new("Animation")
	useGrill.AnimationId = "rbxassetid://9239035638"
	local useGrillTrack = animator:LoadAnimation(useGrill)
	
	local grillFire = Instance.new("Fire")
	grillFire.Parent = grillCooker
	wait(0.4)
	useGrillTrack:Play()
	useGrillTrack.Stopped:Wait()
	wait(2)
	grillFire:Destroy()
end

I am calling this function here:

game.ReplicatedStorage.FireAppetizers.FireAvocado.OnServerEvent:Connect(useGrillToCook)

I want to change it to this:

game.ReplicatedStorage.FireAppetizers.FireAvocado.OnServerEvent:Connect(function()
	useGrillToCook()
end)

I want to change it because I will have many foods that each have a different cooking process, and I have many functions that could be possible steps in cooking. The first one to call the function works, but for the second one, it says it attempted to index nil with “Character”. I’m not sure what to do. Any ideas?

If you look at your local function local function useGrillToCook(plr,grill).
You haven’t passed down your plr and grill arguments to useGrillToCook() when you’re calling for that function.

So instead, it should be something like:

game.ReplicatedStorage.FireAppetizers.FireAvocado.OnServerEvent:Connect(function(plr, grill)
	useGrillToCook(plr, grill)
end)

Also, I don’t see why you should be animating the player on the server in the first place. Animations do replicate from client to server.

That didn’t work. It’s still giving the same error. I think the arguments are being passed through the line that calls the FireAvocado event. Here is the line:

game.ReplicatedStorage.FireAppetizers.FireAvocado:FireServer(selectedGrill)

This line is in a local script in starter player scripts btw.