Keep getting the error "attempt to yield across metamethod/C-call boundary"

Hello. I am trying to make a server script wait a set amount of time that I sent over a remote event from local script (offset) before firing the client but every time I run it with the wait(offset) it says attempt to yield across metamethod/C-call boundary. I have no clue what I am doing wrong or how to fix this. Here is my code for the server script.

local E = game.ReplicatedStorage.Events
local SA = E:FindFirstChild("SA")

SA.OnServerEvent:Connect(function(player, keyName, offset)
	keyName:gsub('(%a*):(.*)', function (first, second)
		print(('\'%s\' : \'%s\''):format(first, second))
		print("Note Recieved: "..keyName)
		local Key = game.ReplicatedStorage.key:Clone()
		local Start = workspace.Game:FindFirstChild(first.."Start")
		local Finish = workspace.Game:FindFirstChild(first.."Finish")
		local Distance = (Start.Position - Finish.Position).magnitude
		Key.Parent = workspace.Notes
		Key.Name = keyName
		Key:SetAttribute("Key", first)
		Key:SetAttribute("Time", offset)
		wait(offset)
		Key:SetAttribute("Hittable", true)
		SA:FireClient(player, keyName, Start, Finish, Distance)
	end)
end)

I’m not sure but it may be because you are trying to yield the RemoteEvent? You could try to do something like:

onServerEvent
wait(time)

Just moved the

wait(offset)
Key:SetAttribute("Hittable", true)

into the local script im so dumb

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.