I’ve been putting the finishing touches on the lighting system for my Backrooms game by adding sounds to the lights flickering, but for some reason I keep getting this error.
Here is the relevant portion of my code (The rest is just functions for light toggling and some variables that has no impact on the sound not working):
while blackoutActive == false do
print("Random flicker function engaged")
selectedLight = math.random(1, 255)
task.wait(math.random(5, 17))
print("Flicker event begining")
fsound = Instance.new("Sound")
fsound.Parent = lights[selectedLight]
fsound.SoundId = "rbxassetid://15558806269"
chance = math.random(1, 61)
fsound.Playing = true
for i = 1, math.random(3, 10) do
lightOff(selectedLight)
task.wait(0.05)
lightOn(selectedLight)
task.wait(0.05)
print("Flicker loop", i)
end
fsound.Playing = false
fsound:Destroy()
print("Blackout chance: ", chance)
if chance == 60 then
blackout()
task.wait(math.random(30, 360))
endBlackout()
end
end
Does anyone know what’s wrong?