Unable to use a String Attribute for comparing

so I’m trying to get a string attribute and compare it in my script so basically I get the attribute and compare it to my strings that I put into the script but the thing is it always returns a true value no matter if the string i put in the script is the same as the attribute or not, is what I’m trying to do impossible or am I doing it wrong? I do think this could be a Studio bug, tell me what you think.

EDIT: this seems to be a bug only with strings as it works fine with numbers.
Code Example:

local part = script.Parent
local attribute = part:GetAttribute("SetColour")

while true do
 if attribute == "Orange" or "orange" then
  part:Destroy()
 end
wait()
end

this is some random code but is a good example of what i mean

1 Like

Maybe it would be easier to help you if you posted a snippet of your code/

1 Like

sorry, just updated the post, have a look

its because ur not updating attribute
add an attribute = part:GetAttribute("SetColour") just before ur if statment inside of the loop

1 Like

but i put in my string before i even run the game, it isnt a script that sets it

ok then for debug purposes print attribute just before the if statment

i did a print before and it gave me the right string, but the If statement did not detect the string, i did this with both right and wrong strings and it seems as the If statement is the broken one as it works fine for wait(Attribute) when i put in a number value.

print attribute and show me the raw result

image

local part = script.Parent
local attribute = part.Value:GetAttribute("SetColour")

while true do
	wait(5)
	print(attribute)
	if attribute == "Orange" or "orange" then
		part:Destroy()
	end
end

part was still destroyed, i used a int value which i added a string attribute to.

Operators don’t work like that. Use this instead:

 if attribute == "Orange" or attribute == "orange" then
  part:Destroy()
 end
3 Likes

remove the 2nd or statment in ur code

1 Like

oh it was the or statement messing it up, thanks

i didnt know that, thank you man