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)
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)