I’m currently playing around with sleitnick right now, and learning it, and I’m playing with the services currently, and I’ve came across a disturbance.
It prints the money fine on the server, and it returns the money amount after calling the method
But when I go to print it out on the client it returns nil, I have been confused about this for quite a while now, and I honestly have no clue on how to get around it.
I guess functions you add into the service, which the controller returns, don’t return promises maybe?
I know I have promises enabled, because I use them while initialising the knit process and starting them
Would it be possible to see the code of your ClickController? It seems like you might be calling :GetClicks() from the controller by mistake instead of from ClickService in the lower half of your second picture.
As far as I know, the following code works:
CLIENT
local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
local Players = game:GetService("Players")
local LOCAL_PLAYER = Players.LocalPlayer
local ClickService
local ClickController = Knit.CreateController({
Name = "ClickController"
})
function ClickController:GetClicks()
local money = ClickService:GetClicks(LOCAL_PLAYER):expect() -- use andThen/catch for proper error handling
return money
end
function ClickController:KnitInit()
-- etc
end
function ClickController:KnitStart()
ClickService = Knit.GetService("ClickService")
print(self:GetClicks()) -- will print on both client and server
end
return ClickController
(you could also just do this without any need for a proxy method)
local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
local ClickService = Knit.CreateService({
Name = "ClickService",
Client = {},
StarterClicks = 10,
PlayerClicks = {}
})
function ClickService.Client:GetClicks(player)
local money = self.Server:GetClicks(player)
print(money, player)
return money
end
function ClickService:GetClicks(player)
local money = self.PlayerClicks[player] or self.StarterClicks
return money
end
function ClickService:KnitInit()
-- .playeradded/removing connections, etc
end
function ClickService:KnitStart()
-- etc
end
return ClickService
Alternatively, you could use Knit Properties with :SetFor() & :Observe() to handle it instead of constantly needing to do promises.
Thank you for this, I pretty much read through your code and compared it to mine, then realised I did one of the most silliest mistakes lol, forgot to return the data in the controller, lol, thankyou for this though