I have a door to a building that I downloaded and am trying to add a bell sound to the door but keep getting 'attempt to index a nil value' error. I tried copying the other sounds and adding my own but it does not work the same for some reason. The close/open sounds work fine.
-- Internal custom properties
local ROTATION_ROOT = script:GetCustomProperty("RotationRoot"):WaitForObject()
local OPEN_SOUND = script:GetCustomProperty("OpenSound"):WaitForObject()
local CLOSE_SOUND = script:GetCustomProperty("CloseSound"):WaitForObject()
local BELL_SOUND = script:GetCustomProperty("SHOP_DOOR_BELL"):WaitForObject()
-- Variable
local previousRotation = 0.0
-- float GetDoorRotation()
-- Gives you the current rotation of the door
function GetDoorRotation()
return ROTATION_ROOT:GetRotation().z / 90.0
end
function Tick(deltaTime)
local doorRotation = GetDoorRotation()
if doorRotation ~= 0.0 and previousRotation == 0.0 and OPEN_SOUND then
OPEN_SOUND:Play()
BELL_SOUND:Play()
end
if doorRotation == 0.0 and previousRotation ~= 0.0 and CLOSE_SOUND then
CLOSE_SOUND:Play()
end
previousRotation = doorRotation
end