Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to Find A Part with a Value?

I am Having an Issue with LightSource trying to Get into NewLight that Contains SectionCabin But It seems It ends up being an Error As showingo the Output:

Script:44: attempt to index boolean with 'FindFirstChild'

And, the Value for SectionCabin & SideSelection are StringValue

Perhaps, This method is Not really the Best way to find a Partname inside of a Value? Any Help on what I need to do to achieve this would be great!

local SectionCabin = script.Parent.MODES.Section_Select.Value
local SideSelection = script.Parent.MODES.Side_Section.Value
--------------------------------------------------------------
local NewLight = LightFile:FindFirstChild(SectionCabin) ~= nil
local LightSource = NewLight:FindFirstChild(SideSelection) --Error Occurs Here!
		
print('FIND')

1 comment

1

it is kinda weird on line 4

2 answers

NewLight is a true or false value. It should be the following:

local NewLight = LightFile:FindFirstChild(SectionCabin)

if NewLight then
	local LightSource = NewLight:FindFirstChild(SideSelection) 
end

3 comments

0

Yeah, Forgot to mention, the Values are not Boolen, They are StringValue.

0

That is not the point he is trying to make. See my answer below for details.

0

It should still work with string values

Your issue lies in your usage of ~=.

local NewLight = LightFile:FindFirstChild(SectionCabin) ~= nil

Think about what this means. We're searching LightFile's children for SelectionCabin. But it doesn't end here, based on your code. You're essentially asking the interpreter if LightFile.SelectionCabin is not equal to nil. This means that NewLight is inherently a boolean value (true or false).

local SectionCabin = script.Parent.MODES.Section_Select.Value
local SideSelection = script.Parent.MODES.Side_Section.Value
--------------------------------------------------------------
local NewLight = LightFile:FindFirstChild(SectionCabin)
local LightSource = NewLight:FindFirstChild(SideSelection)

print('FIND')

I can't help with anything else if it continues to error, because I can't see the rest of your code. This solves your current error, though.

As a side note, watch out when storing values in variables. If I have an IntValue serving as a player's leaderstat, for example:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Model")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local Kills = Instance.new("IntValue")
	Kills.Name = "Kills"
	Kills.Parent = leaderstats
	-------------
	--do some code in between

	local PlayerKills = Kills.Value
end)

This is important. If you declare PlayerKills as Kills.Value, it may have unexpected behavior. For example, if you declare this variable, and the value of Kills changes, it is important to note that PlayerKills will not change with it. It is, at this point, static.

There is a time and place for declaring variables like this, but you simply have to know when and where it is!

This discussion is preserved as it was. New answers, comments, and votes are closed.