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

What is the problem with my playMusic script? [RESOLVED]

It works in Play Solo but it does not work when you actually play the game. What is the problem?

function playMusic()
	game.Players:WaitForChild("Player")
	if game.Players:findFirstChild("Player") ~= nil then
		game.Workspace.Music:Play()		
	end
end
repeat wait(0.1) until game.Workspace.Music ~= nil
playMusic()

It is a local script, by the way.

1 answer

✓ Accepted answer

The player is only named 'Player' when you're on PlaySolo. Any other time it's the same name as the person's username. Your script will therefore eternally wait on line 02, since there will never be someone named 'Player' in the actual game.

If you want the music to play whenever the game starts, then you don't need anything nearly as complicated. Just put this code inside the sound:

script.Parent:Play()

It will make the sound play as soon as the game starts.

2 comments

0

I know, but for some people the sound asset doesn't load if they lag. Thank you anyway though.

0

You can search preloading on the wiki and learn to prevent that.

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