In the part I have the attribute set to false by default, and when the part gets clicked, the attribute gets changed to true, and vis versa. However, when I check to see whether its true or false for a UI I’m making, it always returns as false even though I see it changing in the properties window.
In short, it’s always printing “open” no matter what, even when the bool is true.
Doorprop = game.Workspace:WaitForChild("movingDoor1")
Door1 = Doorprop:GetAttribute("IsClosed")
function attributeChanged()
if Door1 == true then
print("close")
else
print("open")
end
end
Doorprop:GetAttributeChangedSignal("IsClosed"):Connect(attributeChanged)
The way you currently have it set up using GetAttribute at the very top of the script, it only checks if it’s closed once.
Try setting the variable for checking if the door is closed inside the function.
local Doorprop = workspace:WaitForChild("movingDoor1")
local DoorClosed
function attributeChanged()
DoorClosed = Doorprop:GetAttribute("IsClosed")
if DoorClosed == true then
print("Close")
else
print("Open")
end
end
Doorprop:GetAttributeChangedSignal("IsClosed"):Connect(attributeChanged)
Edit: You can also opt to turn the variable for DoorClosed into a function that returns true or false. I’d recommend this because it can work well for many doors
local Doorprop = workspace:WaitForChild("movingDoor1")
local function DoorClosed(door) : boolean
return door:GetAttribute("IsClosed") == true
end
function attributeChanged(door)
return function()
print(DoorClosed(door) and "Closed" or "Open")
end
end
Doorprop:GetAttributeChangedSignal("IsClosed"):Connect(attributeChanged(Doorprop))
Doorprop = game.Workspace:WaitForChild("movingDoor1")
Door1 = Doorprop:GetAttribute("IsClosed")
function attributeChanged()
if Doorprop:GetAttribute("IsClosed") == true then
print("close")
else
print("open")
end
end
Doorprop:GetAttributeChangedSignal("IsClosed"):Connect(attributeChanged)