Attempt to index nil with 'FindFirstChild'

I’m new to the dev forum, this is my first post. Thank you for understanding.

I’m currently a beginner scripter trying to figure out what I did wrong here. I’m trying to achieve a system in short that, you need a crystal saved in a folder in your player to change the color of a lightsaber.
if you need extra info, these are solarhorizons lightsabers, available open-sourced.

in the tools server script, there is a function called recolor. I am modifying it here.

	Recolor = function(data,plr)
		local TargetBlade
		if Dual then
			TargetBlade = {
				[1] = ActiveSabers[1].Blade,
			}
			if ActiveSabers[2] then
				TargetBlade[2] = ActiveSabers[2].Blade
			end
		else
			TargetBlade = Blades
		end
		for _, Blade in next, TargetBlade do

			local Target = "Emitter"
			if Blade.Name == "Blade2" then
				Target = "Emitter2"
			end
			Blade.FX.Glow.Color = data.Outer
			for _, v in next, Blade[Target]:GetChildren() do            
				if data[v.Name] then
					if plr:FindFirstChild("Crystals"):FindFirstChild("Green") then
						v.Color = ColorSequence.new(data[v.Name])
					end
				else
					v.Color = ColorSequence.new(data.Outer, data.Inner)
				end
			end

		end
	end,

it uses a module script to get color data and keys, if I pressed g the lightsaber would turn green.
this is where the problem lies. when I modified it, I got the error that states:


this is the error, ive narrowed it down to the part I’ve added which is this line (i think)

if plr:FindFirstChild("Crystals"):FindFirstChild("Green") then

the green crystal is a bool value in a folder in my player. there will be other colors in there too.
I am still new and do not understand a lot of things. explaining it simply would help alot, and if you have questions you can ask. thanks alot!

The error is saying that Crystals is nil. Check for Crystal’s existence first, then check if Green is inside that.

I can verify the crystal is in the folder.

image

or am I getting it wrong?

If crystals isn’t nil then plr is nil. Where do you define plr?

Oh! I don’t think I did!

how can I get a player for it though?

do I use a player added function?

Well then that would be the problem :sweat_smile:

If this is a server script then yeah you’d have to use the player added event. You want the code to run whenever someone joins, and in order to do that you’d need to use PlayerAdded.

game.Players.PlayerAdded:Connect(function(plr)
    -- the rest of your code
end)