Currently adding sound to my lockdown system and it says…
I’m unsure of why this is happening other than maybe a GetChildren:() error?
local LockdownButton = script.Parent
local clickDetector = LockdownButton.ClickDetector
local clicked = false
local lights = game.Workspace.Lights
local SoundParts = game.Workspace.SoundParts
function onMouseClick()
if not clicked then
clicked = true
LockdownButton.BrickColor = BrickColor.Red()
for k, Sound in pairs(SoundParts:getChildren()) do
wait()
Sound.Playing = true
wait(9)
Sound.Playing = false
end
for k, light in pairs(lights:getChildren()) do
wait()
light.Light.Color= Color3.fromRGB(255, 58, 58)
end
else
clicked = false
LockdownButton.BrickColor = BrickColor.Green()
for k, light in pairs(lights:getChildren()) do
wait()
light.Light.Color= Color3.fromRGB(255, 255, 255)
end
end
end
clickDetector.MouseClick:connect(onMouseClick)
The sounds are attached to the Part instances, and you’re trying to play the Part itself, which is not a sound. Try this:
for k, Sound in pairs(SoundParts:getChildren()) do
if Sound:FindFirstChild("Sound") then
wait()
Sound["Sound"].Playing = true
wait(9)
Sound["Sound"].Playing = false
end
end
local LockdownButton = script.Parent
local clickDetector = LockdownButton.ClickDetector
local clicked = false
local lights = game.Workspace.Lights
local SoundParts = game.Workspace.SoundParts
function onMouseClick()
if not clicked then
clicked = true
LockdownButton.BrickColor = BrickColor.Red()
for k, Sound in pairs(SoundParts:getChildren()) do
wait()
Sound.Sound.Playing = true
wait(9)
Sound.Sound.Playing = false
end
for k, light in pairs(lights:getChildren()) do
wait()
light.Light.Color= Color3.fromRGB(255, 58, 58)
end
else
clicked = false
LockdownButton.BrickColor = BrickColor.Green()
for k, light in pairs(lights:getChildren()) do
wait()
light.Light.Color= Color3.fromRGB(255, 255, 255)
end
end
end
clickDetector.MouseClick:connect(onMouseClick)