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

How do I make a onspawn audio music script?

I tried asking friends but they didn't know and I tried the lua forum and it didnt help me much!

1 comment

0

Can anyone please respon to this?

2 answers

✓ Accepted answer

It would be more helpful if you told us where the audio is. Other than that, a localscript in startergui:

audio=Instance.new("Sound",game.Players.LocalPlayer)
audio.Looped=true
audio:play()

To do this is simple you just need to set up a few things First put a LocalScript in the StarterGui Next place a Sound object inside of the LocalScript and set up the SoundId Then name the sound "OnSpawn" (Important!) Lastly put one of the two codes (see below) in the LocalScript

If you want to play the music only the first time a player joins a server use this code :

player = game:GetService("Players").LocalPlayer
sound = script.Parent:FindFirstChild("OnSpawn")
content = game:GetService("ContentProvider")
content:Preload(sound.SoundId)

if player:FindFirstChild("FirstTime") == nil then
	Instance.new("Flag",player).Name = "FirstTime"
	sound:Play()
end

If you want to play the music every time the player spawns use this code :

player = game:GetService("Players").LocalPlayer
sound = script.Parent:FindFirstChild("OnSpawn")
content = game:GetService("ContentProvider")
content:Preload(sound.SoundId)

sound:Play()

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

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