0
\$\begingroup\$

I've been trying for a few days now to get my background music to work on one of my Roblox places, but every time I get the error:

13:50:23.806 - Players.PungentZeus0.PlayerGui.bgmusic:21: attempt to index global 'Sound' (a nil value)

Here's the code:

local ContentProvider = game:GetService("ContentProvider")

local pageTurnId = "rbxassetid://144585389"

local sound = Instance.new("Sound")
sound.SoundId = pageTurnId

local assets = { sound }

ContentProvider:PreloadAsync(assets)

print("All assets loaded.")

local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://144585389"

if not sound.IsLoaded then
    sound.Loaded:wait()
end

Sound:Play()
\$\endgroup\$
1
\$\begingroup\$

It turns out that I simply forgot to put the whole command:

Workspace.Sound:Play()

It now works as expected.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.