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

How do I fix the words that are red in my code?

i am a complete beginner, i'm just following a few youtube tutorials to make a button that plays music

the words "function" "local" "while" "do" and "end" are all in red, and i'm really not sure how to fix it. it asked if i had made sure to close "do" at line 7, and i have absolutely no idea what that means. can someone explain to me in layman's terms what i'm doing wrong and how to fix it?

game.Workspace["click detector event"].onServerEvent:connect(function()

local musicFolder = game.ReplicatedStorage.Music
local availableMusic = musicFolder:GetChildren()
local currentTrack = game.ReplicatedStorage.CurrentTrack

while true do

	local randomTrack = availableMusic	[math.random(1,#availableMusic)]

	currentTrack = "..." -- nothing is playing yet

	wait(1) -- delay before next song

	randomTrack:Play()

	currentTrack.Value = randomTrack.Name

	wait(randomTrack.TimeLength)

end)

1 comment

0

I'm not sure what your settings are for the color schemes in code but unless there is an underline, only then it's a problem, otherwise you are doing everything fine. All I really see is, you need an extra "end" behind "end)", exactly how I spelled it. Also I'm assuming the rest of the code won't work because of line 9

2 answers

Your main problem is that you don't have an extra end to your code. Therefore, causing it to break. Because it doesn't know WHERE to end. The easiest way to fix your code would be to put an end above the end) on line 14. You'll place this, on line 13. Here's a code that basically fixes this for you.

game.Workspace["click detector event"].OnServerEvent:Connect(function() --end on line 14
    local musicFolder = game.ReplicatedStorage.Music
    local availableMusic = musicFolder:GetChildren()
    local currentTrack = game.ReplicatedStorage.CurrentTrack

    while true do --This statement creates the end on line 13.
        local randomTrack = availableMusic[math.random(1,#availableMusic)]
        currentTrack.Value = nil
        wait()
        randomTrack:Play()
        currentTrack.Value = randomTrack.Name
        wait(randomTrack.TimeLength)
    end --Placed.
end)

--[[
I hope this fixed it.]]

i think you are missing an "end"

game.Workspace["click detector event"].OnServerEvent:Connect(function()
	local musicFolder = game.ReplicatedStorage.Music
	local availableMusic = musicFolder:GetChildren()
	local currentTrack = game.ReplicatedStorage.CurrentTrack

	while true do
		local randomTrack = availableMusic[math.random(1,#availableMusic)]
		currentTrack.Value = nil
		wait()
		randomTrack:Play()
		currentTrack.Value = randomTrack.Name
		wait(randomTrack.TimeLength)
	end -- this is the end you are missing
end)

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