Coroutine.wrap isn't getting called

Hello! I’m trying to make one of the Hardest Obbies on ROBLOX, I’m making locations like the bottom and top of the mountain, So I’m making GUI Notifications.

Whenever I call the Coroutine.wrap I get this error

  09:26:33.670  Workspace.NubblyFry.CheckPointScript:16: Argument 1 missing or nil  -  Client - CheckPointScript:16
  09:26:33.671  Stack Begin  -  Studio
  09:26:33.672  Script 'Workspace.NubblyFry.CheckPointScript', Line 16  -  Studio - CheckPointScript:16
  09:26:33.675  Stack End  -  Studio
  09:26:38.239  0.5, 0.5  -  Server
  09:26:39.006  0.5, 0.5  -  Client

Here is the Script:

local Character = script.Parent
local Head = script.Parent:WaitForChild("Head")
local Torso = script.Parent:WaitForChild("Torso")
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local LeftLeg = script.Parent:WaitForChild("Left Leg")
local RightLeg = script.Parent:WaitForChild("Right Leg")
local LeftArm = script.Parent:WaitForChild("Left Arm")
local RightArm = script.Parent:WaitForChild("Right Arm")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CheckPoint1Event = ReplicatedStorage:WaitForChild("CheckPoint1Event")

local CheckPointMSG1 = coroutine.wrap(function()
	CheckPoint1Event:FireClient()
end)

LeftLeg.Touched:Connect(CheckPointMSG1())
RightLeg.Touched:Connect(CheckPointMSG1())

Change this

to this

LeftLeg.Touched:Connect(CheckPointMSG1)
RightLeg.Touched:Connect(CheckPointMSG1)

It works up to a point, but it would be better to leave it as a normal function.

1 Like

Uhhhh.wav

 09:37:07.950  Argument 1 missing or nil  -  Client
  09:37:07.951  cannot resume dead coroutine  -  Client
  09:37:09.215  cannot resume dead coroutine  -  Client
  09:37:09.215  cannot resume dead coroutine  -  Client
  09:37:10.247  cannot resume dead coroutine  -  Client
  09:37:10.247  cannot resume dead coroutine  -  Client
  09:37:10.694  cannot resume dead coroutine  -  Client
  09:37:10.764  cannot resume dead coroutine  -  Client
  09:37:10.779  cannot resume dead coroutine  -  Client
  09:37:10.797  cannot resume dead coroutine  -  Client
  09:37:10.943  bad allocation  -  Client
  09:37:10.944  Requested module experienced an error while loading  -  Client
  09:37:10.944  Requested module experienced an error while loading  -  Client
  09:37:10.946  cannot resume dead coroutine  -  Client
  09:37:10.946  cannot resume dead coroutine  -  Client
  09:37:10.981  cannot resume dead coroutine  -  Client
  09:37:11.078  cannot resume dead coroutine  -  Client
  09:37:11.079  cannot resume dead coroutine  -  Client
  09:37:11.162  cannot resume dead coroutine  -  Client
  09:37:11.295  cannot resume dead coroutine  -  Client
  09:37:11.762  cannot resume dead coroutine  -  Client
  09:37:11.762  cannot resume dead coroutine  -  Client
  09:37:12.438  cannot resume dead coroutine  -  Client
  09:37:12.440  cannot resume dead coroutine  -  Client
  09:37:13.562  cannot resume dead coroutine  -  Client
  09:37:13.562  cannot resume dead coroutine  -  Client
  09:37:14.561  cannot resume dead coroutine  -  Client
  09:37:14.561  cannot resume dead coroutine  -  Client
  09:37:15.564  cannot resume dead coroutine  -  Client
  09:37:15.565  cannot resume dead coroutine  -  Client
  09:37:16.211  cannot resume dead coroutine  -  Client
  09:37:16.211  cannot resume dead coroutine  -  Client
  09:37:16.312  cannot resume dead coroutine  -  Client
  09:37:16.445  cannot resume dead coroutine  -  Client
  09:37:16.479  cannot resume dead coroutine  -  Client
  09:37:16.479  cannot resume dead coroutine  -  Client
  09:37:16.655  cannot resume dead coroutine  -  Client
  09:37:17.261  cannot resume dead coroutine  -  Client
  09:37:17.262  cannot resume dead coroutine  -  Client
  09:37:17.612  cannot resume dead coroutine  -  Client
  09:37:17.612  cannot resume dead coroutine  -  Client
  09:37:18.061  cannot resume dead coroutine  -  Client
  09:37:19.044  cannot resume dead coroutine  -  Client
  09:37:19.045  cannot resume dead coroutine  -  Client
  09:37:20.061  cannot resume dead coroutine  -  Client
  09:37:20.061  cannot resume dead coroutine  -  Client
  09:37:21.060  cannot resume dead coroutine  -  Client
  09:37:21.061  cannot resume dead coroutine  -  Client
  09:37:22.062  cannot resume dead coroutine  -  Client
  09:37:22.063  cannot resume dead coroutine  -  Client
  09:37:23.061  cannot resume dead coroutine  -  Client
  09:37:23.062  cannot resume dead coroutine  -  Client
  09:37:24.060  cannot resume dead coroutine  -  Client
  09:37:24.060  cannot resume dead coroutine  -  Client
  09:37:25.062  cannot resume dead coroutine  -  Client
  09:37:25.063  cannot resume dead coroutine  -  Client
  09:37:26.061  cannot resume dead coroutine  -  Client
  09:37:26.062  cannot resume dead coroutine  -  Client
  09:37:27.061  cannot resume dead coroutine  -  Client
  09:37:27.061  cannot resume dead coroutine  -  Client
  09:37:28.060  cannot resume dead coroutine  -  Client
  09:37:28.061  cannot resume dead coroutine  -  Client
  09:37:29.061  cannot resume dead coroutine  -  Client
  09:37:29.061  cannot resume dead coroutine  -  Client
  09:37:30.061  cannot resume dead coroutine  -  Client
  09:37:30.061  cannot resume dead coroutine  -  Client
  09:37:31.076  cannot resume dead coroutine  -  Client
  09:37:33.076  cannot resume dead coroutine  -  Client
  09:37:33.077  cannot resume dead coroutine  -  Client
  09:37:34.083  cannot resume dead coroutine  -  Client
  09:37:34.085  cannot resume dead coroutine  -  Client
  09:37:35.077  cannot resume dead coroutine  -  Client
  09:37:35.077  cannot resume dead coroutine  -  Client
  09:37:36.095  cannot resume dead coroutine  -  Client
  09:37:36.095  cannot resume dead coroutine  -  Client
  09:37:37.143  cannot resume dead coroutine  -  Client
  09:37:37.144  cannot resume dead coroutine  -  Client
  09:37:38.127  cannot resume dead coroutine  -  Client
  09:37:38.128  cannot resume dead coroutine  -  Client
  09:37:41.148  cannot resume dead coroutine  -  Client
  09:37:41.148  cannot resume dead coroutine  -  Client
  09:37:42.161  cannot resume dead coroutine  -  Client
  09:37:42.161  cannot resume dead coroutine  -  Client
  09:37:43.161  cannot resume dead coroutine  -  Client
  09:37:43.161  cannot resume dead coroutine  -  Client
  09:37:44.160  cannot resume dead coroutine  -  Client
  09:37:44.160  cannot resume dead coroutine  -  Client
  09:37:45.150  cannot resume dead coroutine  -  Client
  09:37:45.151  cannot resume dead coroutine  -  Client
  09:37:46.160  cannot resume dead coroutine  -  Client
  09:37:46.160  cannot resume dead coroutine  -  Client
  09:37:47.159  cannot resume dead coroutine  -  Client
  09:37:47.160  cannot resume dead coroutine  -  Client
  09:37:48.160  cannot resume dead coroutine  -  Client
  09:37:48.160  cannot resume dead coroutine  -  Client
  09:37:49.159  cannot resume dead coroutine  -  Client

Focus on the Argument 1 Missing or nil

How would I revive the Coroutine though?

Why are you wrapping FireClient() in a coroutine at all?

Since I’m still learning about scripting, I like to re-use types of things I’m trying to learn to memorize it, Would it work If I didn’t?

When I changed it to this, it still didn’t work for some reason

  09:45:03.408  Argument 1 missing or nil  -  Client - CheckPointScript:14
local Character = script.Parent
local Head = script.Parent:WaitForChild("Head")
local Torso = script.Parent:WaitForChild("Torso")
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local LeftLeg = script.Parent:WaitForChild("Left Leg")
local RightLeg = script.Parent:WaitForChild("Right Leg")
local LeftArm = script.Parent:WaitForChild("Left Arm")
local RightArm = script.Parent:WaitForChild("Right Arm")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CheckPoint1Event = ReplicatedStorage:WaitForChild("CheckPoint1Event")

local function LegsTouched(hit)
	if hit.Name == "SpawnLocation" then
		CheckPoint1Event:FireClient() - Line 14
	end
end

LeftLeg.Touched:Connect(LegsTouched)
RightLeg.Touched:Connect(LegsTouched)

That’s the problem, just connect it in as a normal function

function CheckPointMSG1()
    CheckPoint1Event:FireClient()
end
LeftLeg.Touched:Connect(CheckPointMSG1)
RightLeg.Touched:Connect(CheckPointMSG1)

or put the coroutine inside if necessary

function CheckPointMSG1()
	coroutine.wrap(function()
		CheckPoint1Event:FireClient()
	end)()
end
LeftLeg.Touched:Connect(CheckPointMSG1)
RightLeg.Touched:Connect(CheckPointMSG1)

Creating a coroutine is like creating another lane on a highway. If one lane gets blocked, the other ones are unaffected.
It is unnecessary to make a coroutine for running something that doesn’t block. (You don’t need a coroutine in the first place.)

However, if you want an answer to this then, @SOTR654 was correct, parantheses should not be present in the :Connect() function!

Also it is not clever to connect .Touched() to a remote without a debounce or cooldown because Touched can fire lots of times a second

3 Likes

Just like it says, you failed to provide an argument that was expected to be there. You called FireClient but it doesn’t know which client you want to fire it on.

Inside the parantheses of FireClient() you need to specify a Player. (Client = Player)

2 Likes

But I need to check if the part that it hit is the spawn location in specific, else if I just used that everywhere I go the Event would fire for the client.

local function LegsTouched(hit)
	if hit.Name == "SpawnLocation" then
		CheckPoint1Event:FireClient()
	end
end

So would I put script.Parent, and how would I find the player?

You aren’t passing a parameter to FireClient. FireClient isn’t asynchronous either so I don’t know why you’d want to create a separate thread anyway. You should also handle your .Touched events on the client and just handle everything relating to the leg touches in a single script but it’s up to you.

Anyway, I assume you’re trying to get the player from the script’s parent. You also should add a debounce

local players = game:GetService('Players')
local player = players:GetPlayerFromCharacter(script.Parent)
local checkpoint1Touched = false
local function checkpointMsg1(hit)
    if checkpoint1Touched then
        return
    end
    checkpoint1Touched = true
    checkPoint1Event:FireClient(player)
end
rightLeg.Touched:Connect(checkpointMsg1)
leftLeg.Touched:Connect(checkpointMsg1)
1 Like

It works, but it says “FireClient can only be called by the Server.”

1 Like

Switch to a BindableEvent and use :Fire and .Event instead of :FireClient and .OnClientEvent respectively.

1 Like

Whats a BindableEvent?


It’s like a remote event but stays on one boundary: the client or the server.