I am trying to check if a attribute is 0 or 1 or all the way to 15. and then set transparency but it isnt working. how do i fix this?
FOUND OUT THAT THE TRANSPARENCY IS NOT WORKING the attrbiute detection works ok but transparency doesnt change
local Wire = script.Parent local Strength = script.Parent.unpowered.Transparency function setSignal() if Wire:GetAttribute("SignalStrength") == 0 then Strength = 0 end if Wire:GetAttribute("SignalStrength") == 1 then Strength = 0.0667*1 end if Wire:GetAttribute("SignalStrength") == 2 then Strength = 0.0667*2 end if Wire:GetAttribute("SignalStrength") == 3 then Strength = 0.0667*3 end if Wire:GetAttribute("SignalStrength") == 4 then Strength = 0.0667*4 end if Wire:GetAttribute("SignalStrength") == 5 then Strength = 0.0667*5 end if Wire:GetAttribute("SignalStrength") == 6 then Strength = 0.0667*6 end if Wire:GetAttribute("SignalStrength") == 7 then Strength = 0.0667*7 end if Wire:GetAttribute("SignalStrength") == 8 then Strength = 0.0667*8 end if Wire:GetAttribute("SignalStrength") == 9 then Strength = 0.0667*9 end if Wire:GetAttribute("SignalStrength") == 10 then Strength = 0.0667*10 end if Wire:GetAttribute("SignalStrength") == 11 then Strength = 0.0667*11 end if Wire:GetAttribute("SignalStrength") == 12 then Strength = 0.0667*12 end if Wire:GetAttribute("SignalStrength") == 13 then Strength = 0.0667*13 end if Wire:GetAttribute("SignalStrength") == 14 then Strength = 0.0667*14 end if Wire:GetAttribute("SignalStrength") == 15 then Strength = 0.0667*15 end end while true do setSignal() wait() end
You're saving a variable Strength which holds the transparency value, however when you change the variable you do not change the transparency value. You should change the transparency value directly:
script.Parent.unpowered.Transparency = 0.0667
It's also worth noting that you can compress all of the if statements into a single line by treating the transparency value as a linear function:
script.Parent.unpowered.Transparency = 0.0667 * Wire:GetAttribute("SignalStrength")
It's also a better idea to make your code event based by connecting to GetAttributeChangedSignal instead of constantly looping:
Wire:GetAttributeChangedSignal("SignalStrength"):Connect(setSignal)
Use GetAttributeChangedSignal()
.
Wire:GetAttributeChangedSignal("SignalStrength"):Connect(function() if Wire:GetAttribute("SignalStrength") <=0 then Wire.unpowered.Transparency = 0 else Wire.unpowered.Transparency = 0.0667 * Wire:GetAttribute("SignalStrength") end end)