Returning value from client to server? (Knit)

How could I do this?

local service = knit.CreateService({ Name = script.Name, Client = { Sync = knit.CreateSignal() } })

...

local returnValue = self.Client["Sync"]:Fire(player, "hi")
--client gets the data where client returns "hello!"
repeat wait() until returnValue ~= nil
print(returnValue)
--expected "hello!" but get nothing (keeps repeating).

Forgot to mention, the client is already listening for the “Sync”.

The ::Fire() method in Roblox is usually reserved for one-way communication, you would usually use ::Invoke() - see here for reference

I had to google Knit’s API, found here, since I’ve not used it - it looks as though they follow the same pattern.

Define your RemoteFunction handler, or in Knit’s terminology a method, like so:

Example
-- server
function SomeService:GetHello(player)
  return 'Hello ' .. player.Name
end

function SomeService.Client:GetHello(player)
  return self.Server:GetHello(player)
end


-- client
local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)

local SomeService = Knit.GetService("SomeService")
SomeService:GetHello():andThen(function (result)
  print(result)
end)

Internally, I imagine the ::andThen denotes that it’s using a promise to handle the asynchronous nature of the ::Invoke call. If you wanted to yield for the result as in your example, you would do this:

local success, result = self.Client:GetHello():await()
if success then
  print(result)
else
  print('Uh oh, some error?')
end