InvokeServer causes yielding even if the function is valid

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? fix InvokeServer from yielding infinitely

  2. What is the issue? InvokeServer causes the script the yield infinitely even if the function is valid with no possible inf yield methods

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

this code is for my tower defense game and it is supposed to place the tower,
tName is the tower name
TowerCFrame is the preview tower cframe
Rotation is the rotation value (number)

I dont know why it doesnt work

--client
mouse.Button1Down:Connect(function()
			print("mouse down")
			local didPlace, reason = remotes.Tower:InvokeServer("Place", tName, TowerCFrame, Rotation)
			print("fired")
			if didPlace then
				cancelPlacing()
				print("Placed Tower")
			else
				warn(reason)
			end
		end)

--server
remotes.Tower.OnServerInvoke = function(plr, method, ...)
	print("invoke server")
	local args = {...}
	if method == "Place" then
		local tower = towers:FindFirstChild(args[1])
		if tower then
			tower = tower:Clone()
			tower:PivotTo(args[2]*CFrame.Angles(0,math.rad(fixRotation(args[3])),0))
			tower.Parent = workspace
			local ray = workspace:Raycast(tower:GetPivot().Position, Vector3.new(0,-(getHalfRigHeight(tower)+0.05),0), newParams({plr.Character, tower}))
			if ray then
				if ray.Instance:FindFirstChild("Placeable") then
					return true
				else
					return false, "Cant place here"
				end
			else
				return false, "Cant place here"
			end
		end
	end
end

code prints “mouse down” but doesnt print “invoke server” (doesnt print fired aswell)

It looks like the remote function might not be getting connected to on the server side. Is there any code above the OnServerInvoke that’s preventing it from running? Try adding a print statement 1 line above it.

the only thing above is it definitions of the variables and functions (no waitforchild or anything tha yields)

The only other possibilities I can think of are that you might be using a module script on the server and forgetting to require it, or that the client and server are not using the same RemoteFunction object. By adding a print statement above the server connection, you should be able to narrow down the issue at least somewhat. If nothing prints, then you know that either the script has yielded somewhere above, or if it’s a module script, it wasn’t properly required. If something does print, then you’re likely not connected to the same RemoteFunction . Let me know if you figure it out.

No module scripts only a working server script and a localscript possible roblox bug (it works on my baseplate made 2 weeks ago)

I am also experiencing this problem. All of a sudden invokeserver is yieling.

Try printing these variables
image

If one of them is nil or doesn’t print it’s probably causing the yield

none of them are nil and all of them are their expected values. 100% stupid roblox bug

Where are all of your scripts located

both scripts work, normal script in serverscriptservice and localscript in startergui (playergui)

Try defining it as

function placeTower()
-- your code goes here
end
RemoteFunctionHere.OnServerInvoke = placeTower

instead of the structure you already used
edit: its a wild guess, don’t judge me

where is the actual remotefunction located and how is it defines on the server and client scripts?

you just did the same thing, just longer

RemoteFunction is in the replicated storage in a folder named remotes

local remote = rep.Remotes.TowerRemote

Do you have a lot of network usage on your place? It could be going into queue

the only way I am able to replicate this is by removing the remote after runtime
maybe make sure the remote and server scripts are still present when the game is running

a few other ways this would give the same result is if your server script is not present or connecting to the remote at runtime or if the script runcontext is set to client

bro its just a baseplate firing a remote when the mouse is down and the remote places a tower cmon :skull:

Its probably a roblox bug or idk I tried the same scripts on a old baseplate and it worked

yeah it seems something is causing that server script to either not connect or be connected to the remote function so its not firing

I tried it in roblox client and still same result idk why its not working