:InvokeServer() doesn't even fire SOMETIMES

Hello, i’ve made a dialogue system and in my localscript i needed to use :InvokeServer() so i can check something from server but it barely fire, and it works only sometimes, ive tried so many things but i couldn’t find the issue

LOCAL SCRIPT:

spawn(function()
	for i,v in pairs(game.Workspace.NPCs:GetChildren()) do
		if v:FindFirstChild("ClickDetector") ~= nil and v:FindFirstChild("Quests") ~= nil then
			if v.Quests:FindFirstChild("Quest") ~= nil then
				if QuestsList[v.Quests.Quest.Value] then
					v.ClickDetector.MouseClick:connect(function()
						if DialogueFrame.Visible == false then
							if Data.ActiveQuest.Value == "" then
								local Check = GetRemote:InvokeServer(Player.Name,"Dialogue",v,v.Quests.Quest.Value)
								repeat
									wait()
								until Check ~= nil
								print(Check)
								if Check == true then
-- Rest of the code


this one part is the issue

SERVER:

GetRemote.OnServerInvoke = function(Player,PName,Name,NPC,QuestName)
	print("1")
	if Name == "Dialogue" then
		if Player.Name == PName and game.Workspace:FindFirstChild(Player.Name) then

I can’t figure out the issue here if anyone can help

I think too much of your code is missing here. Could you post the whole thing here? Otherwise I’m not sure there’s too much we can do for you.

I will say that this part here:

local Check = GetRemote:InvokeServer(Player.Name,"Dialogue",v,v.Quests.Quest.Value)
repeat
	wait()
until Check ~= nil

The repeat here is unnecessary, because InvokeServer is a yielding function and so your script won’t proceed until there’s a response from the server. See https://developer.roblox.com/en-us/api-reference/function/RemoteFunction/InvokeServer for further details.

If I’m not mistaken the code I mentioned above could actually just be the first line and the rest is unnecessary.

But if you could provide a bit more code and maybe tell us what you’re seeing I think we could probably solve this without too much trouble.


this is everything above that line

I guess i solved it by putting this line
local QuestsList = require(game.ReplicatedStorage:WaitForChild("Quests"):WaitForChild("QuestsList"))
under this line
v.ClickDetector.MouseClick:connect(function()

and it somehow worked without breaking now, i’m so confused right now

It’s tough to say without seeing all of the code. You’ve only shown us the first half. I’m guessing something happens after the if check == true then line.

that part is not necessary cuz the problem is from the invokeserver line
it returns “nil” most of the time and i’ve tried putting a print before and after it and they all print