Help With Coroutine Error

Hello, I am getting an error when I try to use coroutines. I’m not really sure what the problem with my code is.

The error:

Players.MegabyteOfficial.PlayerGui.NotificationFrame.LocalScript:78: missing argument #1 to 'create' (function expected)

The code:

function CreateToolTip(TopText, BottomText)
	if TopText ~= nil then
		print("This client is now creating a notification with TopText: " .. TopText .. " | BottomText: " .. BottomText)
		ShowContents()
		Frame.Size = UDim2.new(0.25, 0, 0.09, 0)
		Frame.Visible = true
		TopTextLabel.Text = TopText
		BottomTextLabel.Text = BottomText
		if TopText == "Bag secured" and script.Parent.Objective.Playing == false then
			script.Parent.Objective:Play()
		end
		Frame.Position = UDim2.new(0.5, 0, -0.125, -32)
		local tween1 = Frame:TweenPosition(
			UDim2.new(0.5, 0, 0.25, -32),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Quad,
			0.75,
			true
		)
		task.wait(4)
		Frame.Visible = false
		task.wait(0.1)
		Frame.Visible = true
		task.wait(0.1)
		Frame.Visible = false
		task.wait(0.1)
		Frame.Visible = true
		task.wait(0.1)
		Frame.Visible = false
		task.wait(0.1)
		Frame.Visible = true
		task.wait(0.1)
		HideContents()
		local tween2 = Frame:TweenSize(
			UDim2.new(0, 0, 0.09, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Quad,
			0.75,
			true 
		)
		task.wait(0.75)
		Frame.Visible = false
	end
end

local coro = nil

function ToolTipHandler(TopText, BottomText)
	if coro ~= nil then
		coroutine.close(coro)
	end
	coro = coroutine.create(CreateToolTip(TopText, BottomText))
	coroutine.resume(coro)
end

Any help would be much appreciated!

You are trying to make a new coroutine with the value returned by the CreateToolTip() function, which in this case is nil. This is how you would actually create a new coroutine.

coro = coroutine.create(CreateToolTip,TopText, BottomText)

Replacing the line with this creates an argument count mismatch, and it doesn’t work.

I found a fix, I did something along the lines of what you were saying in your answer but put the parameters in the resume part instead.

coroutine.resume(coro, TopText, BottomText)
1 Like

coroutine.create expects a single function value passed to it.

1 Like

smh so dumb from me. Just forgot that coroutine.resume takes the arguments and not coroutine.create.