How to stop all sounds in a script

i have this script and was wondering any way that when the function is activated, along with what it should do, it also stops all sounds in soundservice, i tried for 30 min and cant find a way

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateRigEvent = ReplicatedStorage:WaitForChild("UpdateRig")
local StarterPlayer = game:GetService("StarterPlayer")
local TypeOfRig = ReplicatedStorage:WaitForChild("TypeOfRig")

local function updateRig(username)
	local player = Players:GetUserIdFromNameAsync(username)
	if player then
		local character = Players:CreateHumanoidModelFromUserId(player)
		if character then
			local rig = workspace:FindFirstChild("Rig")
			local rigPosition = rig and rig:GetPivot() or CFrame.new(0, 0, 0)
			if rig then
				rig:Destroy()
			end
			character.Name = "Rig"
			character.Humanoid.DisplayName = username
			character.Parent = workspace
			character:PivotTo(rigPosition)
			-- Adjust the position to ensure it's not stuck in the ground
			local rootPart = character:FindFirstChild("HumanoidRootPart")
			if rootPart then
				rootPart.CFrame = rigPosition + Vector3.new(0, 0, 0) -- Adjust the Y offset as needed
            end
			-- Detect rig type and update TypeOfRig StringValue
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				if humanoid.RigType == Enum.HumanoidRigType.R6 then
					TypeOfRig.Value = "R6"
					print("New rig is R6")
				elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
					TypeOfRig.Value = "R15"
					print("New rig is R15")
				else
					warn("Unknown rig type detected")
				end
			else
				warn("Humanoid not found in the new character")
			end
		else
			warn("Failed to create character for user: " .. username)
		end
	else
		warn("Failed to get player from username: " .. username)
	end
end

UpdateRigEvent.OnServerEvent:Connect(function(player, username)
	updateRig(username)
end)


1 Like

Just loop thru all of the sounds in soundService and call :Stop() on them.

i did that it didnt work for some reason no errors came

1 Like

Either there is something else that is playing the sounds after you stopped them or your loop didn’t run. There is no way that this doesn’t just work.

nvm i just fixed it by stopping all of the sounds before i play a sound, in another script

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.