Check if a bool attribute

I have some code that gets all the attributes in a script on change but I want it to detect if its a bool value then to only do something as I have some string ones but it is interfering with it;

for name, value in pairs(script:GetAttributes()) do
	script:GetAttributeChangedSignal(name):Connect(function()
		if script:GetAttribute(name) == true then
			
		else
			
		end
	end)
end

Check the type of the value.

local value = script:GetAttribute(name)
print(type(value) == "boolean")

I find it a little curious that you’re saying changes to string attributes are interfering with this code though since you’re performing an explicit check when an attribute with a given name changes and then checking the value of it – shouldn’t be the case. You may want to do some more debugging in that regard because you shouldn’t need to do anything special here.

2 Likes

exactly I dont get why either I tried some stuff

You’re applying this connection to every attribute. The GetAttribute(name) == true check would be false on strings and they run the code in the else block.

If that’s what you meant.

This should work:

if type(script:GetAttribute(name)) == “boolean” then

– (your code here)