Services
Services are module scripts that serve a specific purpose. For example a experience may have a service for GameUI, Points, etc.
Creating a service
You can create a service by creating a new ModuleScript under one of Knights Services folders. Learn how to find knight service folders Folders explanation.
Template
Each service is structured with this template.
local Knight = {
ServiceName = script.Name,
ServiceData = {
Author = "vq9o",
Description = "Example Service example"
},
CanStart = true,
CanUpdate = true,
}
function Knight.Init()
warn("Example Service inited!")
end
function Knight.Start()
warn("Example Service Started!")
end
function Knight.Update(DeltaFrame)
warn("Example Service called for new frame!")
end
return Knight
Default Functions
function Knight.Init() -- optional. Called on init
end
function Knight.Start() -- optional. Called on start
end
function Knight.Update(deltaTime) -- optional. Called on every frame.
end
Init
local Knight = {
ServiceName = script.Name,
ServiceData = {
Author = "vq9o",
Description = "Example Service example"
}
}
function Knight.Init()
-- Client services only.
print(Knight.Player.Name) -- Prints LocalPlayer name
-- All services can access this.
Knight.Shared -- indexs shared, you can access everything in it.
Knight. -- indexs your current runtype (client or server)
Knight.Knight -- returns knight internal functions
-- Example you can call another function bar from service foo without need of using
-- Roblox's require().
Knight.Services.foo.bar()
end
return Knight
Config
CanStart, CanUpdate, CanInit variable allow execution of the .Update(), .Start(), and .Init(). Useful if your using a third-party module and you need to disable Knight from calling its default start function like CameraShaker.
Config is not required and will default to true.
Priority Startup
Folders named as "Database" will have first priority to init, then folders named "Priority" will init. Useful to load core game backend first.
Last updated
Was this helpful?