Help with this script I don't quite understand how to create a script for this.
A script that plays audio when someone spawns (Not Looped) and only you can hear it not other users.
And is the script a Local Script or a normal Script?,Where do I place it?(ex;Serverstorage,Replicated Storage.
LocalScript in StarterGui
repeat wait() until game.Players.LocalPlayer.Character local Player = game.Players.LocalPlayer local Sound = Instance.new("Sound", Player.PlayerGui) Sound.SounId = 0 --YOURSOUNDID Sound.Volume = 1 --Sound.etc, change whatever settings. Sound:Play()
It's normally best to use regular scripts for things like this.
Instead of using a LocalScript
in StarterGui
, use a regular script in ServerScriptService
.
To get the Player, use a PlayerAdded
Event. Like this,
game.Players.PlayerAdded:connect(function(plr) end)
The above gives us the LocalPlayer, in a way.
Now to play a sound Locally, simply place the sound inside of the player. First, let's make the sound using Instance.new()
.
game.Players.PlayerAdded:connect(function(plr) local Sound = Instance.new("Sound",plr)--makes a sound and puts it in the player end)
Now all we have to do is set the volume of the sound, the id of the sound, and play the sound! Here's what your script would look like,
--Regular script in ServerScriptService game.Players.PlayerAdded:connect(function(plr) local Sound = Instance.new("Sound",plr)--makes a sound and puts it in the player Sound.SoundId = 0--Get your sound Id! Sound.Volume = 1--Sound Volume Sound:Play() end)
This would be your script if you only wanted it to play once. However, if you want it to play whenever the player respawns, use a CharacterAdded
Event. Like this,
--Regular script in ServerScriptService game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(char)--Character Added local Sound = Instance.new("Sound",plr) Sound.SoundId = 0 Sound.Volume = 1 Sound:Play() end) end)
That would make the sound play whenever the Character Respawns.
That's all.
Good Luck!