How to use Knit with StarterCharacterScripts

I’m currently trying to use Knit to form an organized project but I don’t know how to use it with the character.

I tested if I could use player.CharacterAdded in StarterPlayerScripts and it worked but I’m not sure if this is good practice because I’ve never seen it.

Example code in StarterPlayerScripts:

local currentCharacter = nil

player.CharacterAdded:Connect(function(character)
	currentCharacter = character
	self:Refresh()
end)

or would I use Knit with StarterCharacterScripts?

1 Like

Using CharacterAdded is probably the best way to do this. I typically avoid using StarterCharacterScripts so that my code is all located in one area. You will need to ensure you run the CharacterAdded function right after you connect to the CharacterAdded event though, just incase there is already a character that won’t be picked up by the CharacterAdded event.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local function CharacterAdded(Character)

end

Player.CharacterAdded:Connect(CharacterAdded)

if Player.Character then
   CharacterAdded(Player.Character)
end

This has worked well for me in the past and I believe it’s standard practice for most developers.

2 Likes

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