This text will be blurred
Yes that is correct.
This text will be blurred
Yes that is correct.
So correct me if I’m wrong but if a attribute is nil then it shouldn’t show up at all
this is a very old thread i didnt know what i was doing and what was that script anyway
I don’t know if you already solve it. But here’s the reason why (I’m not really good at scripting but probably know the reason by experiences.)
So, basically. You have to check for the both reason that are mixed up.
If I’m correct, let me tell you an example:
Let say I have a bool attribute name “Active” that is set to true inside part and a script that’s a child of a part.
local part = script.Parent
-- exist and also set to true
print(part:GetAttribute("Active")) -- true
What if i set the attribute to false:
local part = script.Parent
-- exist and also set to false
print(part:GetAttribute("Active")) -- false
What if the attribute doesn’t exist:
local part = script.Parent
-- if not exist and also check for value
print(part:GetAttribute("Active")) -- nil
In your case, I’m gonna change attribute to yours (name “IgnoreDown”, type “string”, value “”)
local part = script.Parent
if part:GetAttribute("IgnoreDown") then print("return") end
--[[ this would print "return" as it is exist, and has a value of ""
which is a string and always return true.]]
So if you have an attribute with a value of “nil” you might have to do like this :
local part = script.Parent
if (part:GetAttribute("IgnoreDown") ~= nil and part:GetAttribute("IgnoreDown") == "nil" then
return
end
-- [[First, you check if the attribute is exist. doing "~= nil" is the best way to
check if attribute is exist or not. If so, check if attribute has a value of "nil". ]]
Let me remind you about how if else statement works:
local a = "hello"
print(a) -- "hello"
print(a=="hello") -- true, a equal to "hello"
print(a=="hi") -- false, a not equal to "hi"
print(a==nil) -- false, the variable "a" is exist.
print(a~=nil) -- true, the variable "a" is exist.
print(not a) -- false, the variable "a" is exist.
Another example:
local b = (a=="hello")
print(b) -- true, because a=="hello" checked for true or false
a = nil
b = (a=="hello")
print(b) -- error, "a" variable is not exist and cannot proceed to check the value.
a = "hello"
b = (a=="hello" and a~=nil)
print(b) -- true, a is equal to "hello" and it's exist.
(I don’t really understand what are you trying to do here, and this kinda confuse you too. But I can give you this information anyway.)
-- Attribute : IgnoreDown (string and has value equal to "")
local part = script.Parent
print(part:GetAttribute("IgnoreDown")) -- "" gets string instead, because it's not in if else statement
if part:GetAttribute("IgnoreDown") then end -- "" gets true, because it's in an if else statement
if part:GetAttribute("IgnoreDown") ~= nil then end -- "" gets true, because it's checking if it's exist.
if part:GetAttribute("IgnoreDown") == nil then end -- "" gets false, because it's checking if it's not exist.
if part:GetAttribute("IgnoreDown") == "" then end -- "" gets true, because the value is equal to ""
if not part:GetAttribute("IgnoreDown") then end
-- first it'll check if it's exist. Otherwise return nil. (when you add "not" for the prefix. It checks either nil or false.)
-- then it'll check for the value if the value compared to something is equal to false.
-- In this case, it is a string value and string always return true.
-- The second check will be ignored. It'll check for first check instead.
Hope this helps!