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

Why is this script not adding a sound to PlayerGui when player resets?

Why is this script not working properly

The script is in StarterCharacterScripts and it is a localscript.

In the script, a new Sound should be added to the player whenever the player resets.

Any help is greatly appreciated!

Here is the coding for the script:

local Player = game.Players.LocalPlayer

if Player.PlayerGui:FindFirstChild("SoundFixGui"):FindFirstChild("BGM") ~= nil then
	--Do Nothing
	else
		local BackgroundMusic = Instance.new("Sound")
		BackgroundMusic.Parent = Player:FindFirstChild("PlayerGui"):FindFirstChild("SoundFixGui")
		BackgroundMusic.Name = "BGM"
		BackgroundMusic.Looped = true
		BackgroundMusic.SoundId = "rbxassetid://256165333"
		BackgroundMusic:Play()
end

script:Destroy()

1 comment

0

When you play, is the script still in StarterCharacterScripts? Take out script:Destroy() if it is

1 answer

✓ Accepted answer

assuming this is the only background music in the game, just put the music inside the player, theres no need to make it as complicated as putting it into starter gui. if you ever want to disable this sound, you can just disable it inside the local player with a button and local script.


game.Players.PlayerAdded:connect(function(p)-- this will fire when a player enters the game

        local BackgroundMusic = Instance.new("Sound")

        BackgroundMusic.Parent = p

        BackgroundMusic.Name = "BGM"

        BackgroundMusic.Looped = true

        BackgroundMusic.SoundId = "rbxassetid://256165333"

        BackgroundMusic:Play()

end)

3 comments

0

The problem is that when the player resets, the sound gets removed

0

But your answer kind of helped, so thank you. I fixed it now.

0

alright, glad i can help, even if its just a little bit

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