Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a onspawn audio music script?

Asked by 10 years ago

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

0
Can anyone please respon to this? OffbeatKing111 5 — 10y

2 answers

Log in to vote
1
Answered by 10 years ago

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()
Ad
Log in to vote
1
Answered by
samfun123 235 Moderation Voter
10 years ago

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!

Answer this question