Issue with Knit framework

I have a bunch of methods in a particular service. I’m exposing one of them to the client.

function UIService:CreateTween(instance: GuiObject, propertyTable: {[string]: any}, length: number, easingStyle: Enum.EasingStyle, ...) -- Hidden Method
    return TweenService:Create(instance, TweenInfo.new(length, easingStyle or Enum.EasingStyle.Sine, ...), propertyTable) -- The tween is made here
end

function UIService.Client:CreateTween(player: Player, ...) -- Exposed Method
    return self.Server:CreateTween(...) -- At this point the tween still exists
end

I also have a controller that uses the said method to create tweens, but the method returns nil when it shouldn’t.

function InteractionController:KnitStart()
    local UIService = Knit.GetService("UIService")

    --//

    local TweenPromptIn  = UIService:CreateTween(Prompt, {Size = UDim2.new(4.5, 0, 4.5, 0)}, .15)
    local TweenPromptOut = UIService:CreateTween(Prompt, {Size = UDim2.new(0, 0, 0, 0)}, .15)

    --//

    print(TweenPromptOut) -- This is equal to nil which it shouldn't
end

I’m not sure what causes this. I also have promises disabled on the client side.

this might be an issue with the Knit lifecycle, based on how the execution model is structure, you may want to utilize :KnitInit() sometimes services may not be ready to be used

so your script would look something like this:

local UIService

function InteractionController:KnitInit()
    UIService = Knit.GetService("UIService")
end

function InteractionController:KnitStart()
    -- ADD YOUR LOGIC HERE
end

this way the services you reference may be ready to be consumed, let me know if this helps

Still nil. But I noticed that other methods work just fine such as.

function UIService:RoundNumber(a: number, b: number)
    return math.floor(a * b) / b
end
1 Like

sorry for the long wait, i was doing some research on this and it turns out roblox does not allow you to return a tween from the server which is crazy, so that is the issue

you can easily solve this by just porting the tween method to some other controller or the controller itself and you shouldn’t have any issues

hope this helps

1 Like