Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.