My scripter needs help on this because it doesn’t work on line 18 he says, can anyone help me?
I can sort of see it in the output saying it’s on line 18 like you said, but not what the error’s about. What was the error exactly? Can you please show what it says?
Idk the scripter didn’t tell me, but he got it figured out tho thanks!
You forgot to actually declare your local constant on line 6.
It should be:
local songName = main:WaitForChild("SongName")
A tip for your scripter: I recommend not using FindFirstChild on your top-level variables if they might not exist yet:
Do not miscategorise posts. Read the category guidelines before making a thread in a category. Cool Creations is for showcasing works, not for getting help. Scripting Support is for receiving help on programming problems. I have recategorised this thread accordingly.
Just to address some anti patterns in the code -
Why not use a LocalScript to work with this?
You’ll run into a lot of issues using a server-script under StarterGui (e.g using Players.LocalPlayer won’t work as expected).
The script.Parent:WaitForChild("Main")
is redundant too, since that’ll almost always exist if the script has replicated for the player, or could be avoided by just placing the script in the lowest order of hierarchy, same with all the FindFirstChild() calls.
I recommend Colbert’s post that addresses incorrect usage for this, linked above.
The error with the code was that asset
wasn’t defined, along with
main:FindFirstChild("SongName")
(SongName).
The while loop could’ve been avoided by using an event-based approach:
local sound
local function play()
local rand = math.random(#soundFolder:GetChildren())
sound = soundFolder:GetChildren()[rand] -- assuming all sounds were objects
sound:Play()
end
play()
sound.Ended:Connect(play) -- continue an endless loop