Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

One of my lines are red and I can't figure out the reason why?

Asked by 3 years ago
Edited 3 years ago

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)

1 answer

Log in to vote
0
Answered by 3 years ago

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)

0
Didn't work sorry, but I did notice that it says an error about stopping the song. It comes back as nil when I try to stop the random song. Also it only works after the first floor for some reason. DocGooseYT 110 — 3y
Ad

Answer this question