You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to learn how to make Knit components. My main goal is for all my components with a tag be able to when touched make a leaderstat go up. I simply do not know where I implement the touch function.
What is the issue? There seems to be a lack of tutorials of any kind on components for knit which I find absurd
What solutions have you tried so far? I’ve looked at the documentation but all the tutorials made by knits creator are all outdated
If anybody could give me a quick run down on knit’s components and possible tell me where I could implement a touch function that would be great. Cheers!
Hello, if you know how to use knit services, then controllers should come by second nature.
the only thing outdated about sleitnick’s tutorials is the names of certain methods, and how components are required (no longer use .AddComponents)
in any case, heres a code example of a simple killpart component :
local rs = game:GetService('ReplicatedStorage')
local Component = require(rs.Packages.Component)
local KillBrick = Component.new{
Tag = 'KillBrick'
}
function KillBrick:Construct()
--create all the logic and requirements for running on start
self.Connection = nil :: RBXScriptConnection?
end
function KillBrick:Start()
--self.Instance is the tagged instance
local part: BasePart = self.Instance
self.Connection = part.Touched:Connect(function(toucher)
local humanoid = toucher.Parent:FindFirstChildOfClass('Humanoid')
if not humanoid then return end
humanoid:TakeDamage(humanoid.MaxHealth)
end)
end
function KillBrick:Stop()
--//cleanup the component
if self.Connection then self.Connection:Disconnect() end
end
return KillBrick