Hey guys. Recently, I started taking advantage of “attributes” and came to realize how handy they are. However, I can’t seem to get the value of an attribute. I’ve tried everything I know of, but nothing I try is able to get the value of the attribute! Any way I can fix this?
First idea:
local Model = script.Parent
local RotScript = script.Parent.RotScript
local TimeBeforeRot = Model:GetAttribute("TimeBeforeRot")
if TimeBeforeRot == 0 then
RotScript.Enabled = true
end
Second idea:
local Model = script.Parent
local RotScript = script.Parent.RotScript
local TimeBeforeRot = Model:GetAttribute("TimeBeforeRot")
if TimeBeforeRot == Model:SetAttribute("TimeBeforeRot", 30) then
RotScript.Enabled = true
end
None of these worked. Thanks a bunch if you decide to help me!
Hi so :SetAttribute() Applies a new value to an instance.
Like this for example part:SetAttribute("Coins", 50)
This will apply a attribute to the part named “Coins” and set the value to 50.
:GetAttribute() Will read the attribute value on an instance. So you use this to get the value of an attribute.
Like this for example part:GetAttribute("Coins") -- Returns 50
if :GetAttribute("Coins") Doesn’t exist it will return nil
What the issue could be is that Model:GetAttribute("TimeBeforeRot") doesn’t exist, so it returns nil. Could you try to do print(Model:GetAttribute("TimeBeforeRot")) and see if it prints nil or a value?
local Model = script.Parent
local RotScript = script.Parent.RotScript
local TimeBeforeRot = Model:GetAttribute("TimeBeforeRot")
if TimeBeforeRot == 30 then
RotScript.Enabled = true
end