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

Sound plays when player joins a game [Easy fix?]

Asked by 6 years ago

So i have this script that should play a sound when someone joins my game, but it doesn't work. Please help me out!

sound = Instance.new("Sound", game.StarterPlayer.StarterPlayerScripts)

sound.Id = "..." sound:Play()

(Also it should play only for you not for eveyone)

0
If you want it to just play for you, you'd have to make the script local. 3ora 54 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Firstly, why would you put a sound inside StarterPlayerScripts which is intended for scripts for the player and Id isnt just three dots or its a placeholder for a ID. You could make this play locally by playing the Sound on a local script and parent the sound to StarterGui so it would play locally.

local player = game.Players.LocalPlayer
local sound = Instance.new("Sound")

sound.SoundId = "rbxassetid://"..--id here
sound.Parent = player.PlayerGui
sound:Play()

also this would have to be a local script since you can only access LocalPlayer on a LocalScript.

NOTE the parent parameter of Instance.new() is deprecated, just set the parent last.

0
Nice DaggerOf_Fly -24 — 6y
0
Man it didnt work Vibesgus 35 — 6y
0
then you doing it wrong User#23365 30 — 6y
0
I dont need it to play locally. Only so you can hear it once you join Vibesgus 35 — 6y
View all comments (6 more)
0
use the PlayerAdded event User#23365 30 — 6y
0
but you said you only wanted the sound to play for you not everyone User#23365 30 — 6y
0
Quick sidenote - there is nothing wrong with having sounds inside of SPS - and they will run perfectly fine. SummerEquinox 643 — 6y
0
yes, but why would you even put it in there  User#23365 30 — 6y
0
Just making the note. I've had IntValues in SPS before as very obscure solutions to problems. Rather than focusing on more pedantic issues it may prove more effective to focus on the actual question; however, with that being said. if OP really wanted a sound in SPS they should put it there manually rather than creating it from a script - which is bound to cause issues. This can be done by creating SummerEquinox 643 — 6y
0
Wow... did my reply just get cut off lol? I'm new to this site. SummerEquinox 643 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Create a sound with your desired ID inside of any client folder (SPS, StarterGui) - then just wait for its creation and play it once it is found.

local Sound = game.Players.LocalPlayer.PlayerGui:WaitForChild("Sound")
Sound:Play()
Log in to vote
0
Answered by
3ora 54
6 years ago

If you want it to just play for one person, you'd have to make a localscript and use "LocalPlayer". So, you'd have to do this:

game.Players.PlayerAdded(function()
    local Sound = Instance.new("Sound")
    Sound.Parent = game.Players.LocalPlayer.PlayerGui
    Sound.SoundId = Id here
    Sound:Play()
end)

Place the LocalScript inside of ServerScriptService as a LocalScript.

0
Also, there are lots of ways on how to do this method. this is just a method using only one object. 3ora 54 — 6y
0
didnt work Vibesgus 35 — 6y

Answer this question