I'm trying to make an elevator game and have audio inside of the elevator. The audio stops if a new floor appears, I made a script to do this and it worked. It was inefficient though because I used a "while true do" so I changed it to work if a value changed. The script is a server script and works but the songs don't work for some reason. Then I realized a word had a red line under it but I didn't know why and couldn't figure it out. I'm still new to scripting so please help.
local Audio = script.Audio Audio.Changed:Connect(function() print("Checking if audio value = 1 or 0") if Audio.Value == 1 then print("Audio Value is 1, playing song") local Songs = script.parent["Songs/Sounds"]:GetChildren() local RandomizedSongs = math.random(1, #Songs) RandomSong = Songs[RandomizedSongs] The "RandomSong" word in this codeline is the one with the red line. RandomSong:Play() print(RandomSong.Name) wait(RandomSong.TimeLength) else if Audio.Value == 0 then print("Audio Value is 0, disabling script and stopping song") RandomSong:Stop() script.Disabled = true return end end end)
Hello, this should work :D.
local Audio = script.Audio Audio.Changed:Connect(function() print("Checking if audio value = 1 or 0") if Audio.Value == 1 then print("Audio Value is 1, playing song") local Songs = script.Parent["Songs/Sounds"]:GetChildren() -- you had badly write letter here, you wrote parent instead of Parent :) local RandomizedSongs = math.random(1, #Songs) RandomSong = Songs[RandomizedSongs] RandomSong:Play() print(RandomSong.Name) wait(RandomSong.TimeLength) else if Audio.Value == 0 then print("Audio Value is 0, disabling script and stopping song") RandomSong:Stop() script.Disabled = true return end end end)