How to use Sounds with PlayerAdded

So I’m trying to make an Intro and I want to add sound to it. When the player joins they get a GUI and a sound but the script for the sound doesn’t work. I tried it myself but couldn’t get far since I didn’t know how to.

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

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

function PlayerGUIstart()
	wait(1)
	sound:Play()
end

Players.PlayerAdded:Connect(PlayerGUIstart)

I want it that when the player joins the sound will play before anything else has been loaded in. Does anyone know how to do that.

Thanks.

1 Like

Try making a local script in replicated first?? And since replicated first is a place where it’ll be loaded first, you have to use waitforchild if you want to access other things.

1 Like

You can use a LocalScript in Replicated First.

1 Like

I there a video that can explain everything cuz I don’t really understand.

Just put a local script in ReplicatedFirst, and type this:

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

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

function PlayerGUIstart()
	wait(1)
	sound:Play()
    sound.Playing = true
end

Players.PlayerAdded:Connect(PlayerGUIstart)
local Players = game:GetService("Players")
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://1175226216"

sound.Loaded:wait()

function PlayerGUIstart()
	wait(1)
	sound:Play()
end

Players.PlayerAdded:Connect(PlayerGUIstart)

This could work

Do I have to put this in Replicated First?

Yes put it in replicated first so that it plays before anything happens

I did but nothing happened. It didn’t work.

Any errors? Or not?? And did you type everything correctly?

Did you put it in a local script?

Yes I did everything correctly but it still didn’t work. And there are no errors.

Do I have to rewrite it cuz I don’t think this is the right way to do it?

maybe try putting the script in startergui

yeah that was the first thing I did.

Ohhhh wait a second

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

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

function PlayerGUIstart()
	wait(1)
	sound:Play()
    sound.Playing = true
    sound.Played:Wait()
    sound:Destroy()
end

Players.LocalPlayer.CharacterAdded:Connect(PlayerGUIstart)

There we go now it should work!

Edit: I tested it and it works! Great music choice @ardaboyroo, just put the script in replicated first. I cannot believe we put PlayerAdded in a local script instead of CharacterAdded, I also added so it destroys the sound after.

1 Like