Knit Controllers create twice when placed in StarterPlayerScripts

  1. What do you want to achieve? I want to store client-only ModuleScripts inside of StarterPlayerScripts (In a “Controllers” folder) that utilize the Knit framework.

  2. What is the issue? Knit reports that a controller (in this case, ScreenResize) was already created when attempting to run the CreateController function from Knit when the game is run.
    image

(When running the game, there are indeed two instances of this creation function being called, but I don’t expect the StarterPlayerScripts one to be called)
image

  1. What solutions have you tried so far? I’ve searched for this issue, but haven’t found anybody else experiencing it.
KnitRuntimeClient.client.lua
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
    local player = Players.LocalPlayer

--Folders
local controllersFolder = player:WaitForChild("PlayerScripts"):WaitForChild("Controllers")
--Modules
local Knit = require(ReplicatedStorage.Packages.Knit)

Knit.AddControllers(controllersFolder)
Knit.AddControllersDeep(controllersFolder)

Knit.Start()

How would I fix this?
Thanks :slightly_smiling_face:

You loaded the controllers twice.

AddControllers and AddControllersDeep are meant to be used together, as shown in a similar case with services here. I’m guessing Knit makes sure scripts that are initialized don’t get initialized twice.

.AddControllers loads all children in the given directory while .AddControllersDeep loads all descendants.

I haven’t changed this script since moving modules from ReplicatedStorage to StarterPlayerScripts. Also, with only AddControllersDeep, this still errors.

Kinda odd, do you have any scripts that require this ScreenResize module?

Sorry to revive this topic, but I struggled with this for a while, and cannot find any other posts about this specific issue.

So for anyone looking for a solution to this here it is: Local script running twice - #2 by Maelstorm_1973

Had the same issue, if your controller module is not parented in StarterPlayerScripts try doing that.