Components tutorial?

You can write your topic however you want, but you need to answer these questions:

  1. 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.

  2. What is the issue? There seems to be a lack of tutorials of any kind on components for knit which I find absurd

  3. 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!

1 Like

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 :cool::

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
1 Like

Wow, I finally feel like I get components now.
Quick question what are those variables where you use colons and how you did:

self.Connection = nil :: RBXScriptConnection?

could you explain what they mean? thanks

it’s just for the autocomplete, i’m telling the editor that self.Connection is of type RBXScriptConnection

it’s called type checking

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.