Should I use RemoteFunctions in this case?

So I have a skill framework system where when the client sends an input, it goes to a module script with a client version of the move (such as holding animations) which always comes first and then you can send a remote event from that Local part to a new script that’ll run the Server part.

This only allows for Client → Server but if I were to need something like Client → Server → Client (for eg. playing the first animation on the client, lets say you’re charging a move. Then you go to the server to do a hitbox check and do damage and then back to the client to add cool effects for optimization.) For this, should I make another local script where the .Server part of the skill can send back to or should I just use RemoteFunctions?

1 Like

Client → Server → Client should be handled with a RemoteFunction. The client can just wait for the invocation of the RemoteFunction to return a value.

For example, if the client asks the server to validate a hit through a RemoteFunction, then the client receiving a true would know the hit was valid and thus it could execute local logic, such as the effects.

-- LocalScript
Tool.Activated:Connect(function()
  -- Bla bla bla
  local ValidHit = RemoteFunction:InvokeServer(data)
  if ValidHit then
    print("Hit!")
  else
    print("Invalid hit")
  end
end)
-- Script listening
function Validate(data)
  -- Validation check goes here
  if valid then return true end

  -- Base case should always be false since it's safer to just invalidate unexpected data
  return false
end

RemoteFunction.OnServerInvoke = Validate

I believe I could also do this to have infinite communication right. (eg. Client → Server → Client → Server → Client → Server if I somehow ever needed that)