I want to make a Loading Screen that plays an intro music when you play the game, but I want the intro music to stop when the user selects which team he’s on. I used SoundService:PlayLocalSound for this, but I can’t seem to stop the music when i call :Stop on the sound. Code (part of it) in LocalScript in ReplicatedFirst
-- Show loading screen and wait for game to be loaded (game.Loaded:Wait())
-- Play Intro music
local SoundService = game:GetService("SoundService")
local sound = game.ReplicatedStorage.Sounds:WaitForChild("Intro"):Clone()
SoundService:PlayLocalSound(sound)
game.Players.LocalPlayer.PlayerGui.ScreenGui.SwitchTeam.Red.MouseButton1Click:Connect(function()
game.ReplicatedStorage.SwitchTeam:FireServer("Red")
sound:Stop()
sound:Destroy()
end)
for i,v in pairs(workspace.Camera:GetChildren()) do
if v.Name == "Loading Sound" then
v:Stop()
v:Destroy()
end
end
local sound = Instance.new("Sound", workspace.Camera)
sound.Volume = 1
sound.SoundId = "rbxassetid://5195523442"
sound.Name = "Loading Sound"
sound.Looped = true
sound:Play()
if sound.Looped ~= true then
game:GetService("Debris"):AddItem(sound, sound.TimeLength)
end
game.Players.LocalPlayer.PlayerGui.ScreenGui.SwitchTeam.Red.MouseButton1Click:Connect(function()
game.ReplicatedStorage.SwitchTeam:FireServer("Red")
if sound ~= nil then
sound:Stop()
sound:Destroy()
end
end)