Attributes are nil

Hello, so pretty much there are a bunch of values in a folder, and those values have attributes in them. But for some reason, the code down below just doesn’t work. I don’t get any errors or anything, nothing is even being printed.

By the way, the script checking the attributes is a local script.

Any help would be appreciated :sunglasses:

 for i, v in pairs(Tracks:GetDescendants()) do
	if v:FindFirstChild("Switch") then
		if v:GetAttribute("Terminus") and v:GetAttribute("Route") then
		print("finding")
		print(terminus)
		print(route)
		print(v:GetAttribute("Terminus"))
		print(v:GetAttribute("Route"))
		if v:GetAttribute("Terminus") == terminus and v:GetAttribute("Route") == route then
			print("getting")
			unswitch_sequence(v.Parent)
			switch_sequence(v.Value)
			print("done")
			end
		end
		end
end

Can you add a print statement after v:FindFirstChild("Switch") then, to ensure that it is actually an attribute issue?

for i, v in pairs(Tracks:GetDescendants()) do
	if v:FindFirstChild("Switch") then
		print("switch has been found")
		if v:GetAttribute("Terminus") and v:GetAttribute("Route") then
		print("finding")
		print(terminus)
		print(route)
		print(v:GetAttribute("Terminus"))
		print(v:GetAttribute("Route"))
		if v:GetAttribute("Terminus") == terminus and v:GetAttribute("Route") == route then
			print("getting")
			unswitch_sequence(v.Parent)
			switch_sequence(v.Value)
			print("done")
			end
		end
		end
end

image

How are you setting the attriputes of it?

The attribute is made in studio, and the attribute is set as soon as the model spawns. And the local script that checks the attribute only runs if the player sits in the seat.

So I don’t think this is a matter of the for loop checking before the attribute is being set.

and the attribute is set as soon as the model spawns

What is the script you are using to set the initial attribute

Wait sorry, I got mixed up with something.

The attributes aren’t set when the player sits in the seat, the attributes are already set in studio. The attributes are checked when the player sits in the seat.

did you even use :SetAttribute(name, value)?

No, it’s already set in studio.

Am I supposed to set it in game instead of changing it in studio beforehand?

alr understandable

no


I’ve removed the “if Get:Attribute” thing and when I print it, it doesn’t even say nil, it’s literally just an empty space. It really doesn’t make any sense for me.

I just found the problem and it’s ridiculous on how I didn’t see this sooner.

The value isn’t accessible by using FindFirstChild, it needs to be accessed using descendants. Sorry for wasting your time guys.

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