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

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

Asked by 3 years ago

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)

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 greatneil80 2647 — 3y

2 answers

Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago
Edited 3 years ago

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.]]
Ad
Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

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)

Answer this question