You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? fix InvokeServer from yielding infinitely
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 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.
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