When starting out it helps to use variables to reference everything you use more than once. E.g.:
local BUILDING_ROTATION_ATTR = "RotationBuilding"
local building = script.Parent
--Increment building's rotation by 45 degrees
local rotation = building:GetAttribute(BUILDING_ROTATION_ATTR)
rotation += Vector3.new(0, 45, 0)
building:SetAttribute(BUILDING_ROTATION_ATTR, rotation)
You could also write a reusable function if you need this kind of code in many places:
function incrementAttr(instance: Instance, attributeName: string, incrementAmount: number): number
local oldValue = instance:GetAttribute(attributeName)
local newValue = oldValue + incrementAmount
instance:SetAttribute(attributeName, newValue)
return newValue --Might as well return the new value, but it's not really needed.
end
function incrementBuildingRotation(building: Model, incrementAmount: number): number
return incrementAttr(building, "RotationBuilding", incrementAmount)
end
--Example
incrementBuildingRotation(building, 45)