--mute button stuff

local canmute = settings.DisplayMuteButton

local musicon = true

function CreateButton()
	local button = script.MuteButton:clone()
	script.MuteButton:Destroy()
	button.Visible = true
	button.MouseButton1Click:connect(function()
		musicon = not musicon
		local bgm = script:FindFirstChild("BGM")
		if bgm then
			bgm.Volume = musicon and bgm.OriginalVolume.Value or 0
		end
	end)
	button.Parent = plr:WaitForChild("PlayerGui").PlayerHud.PlayerHUD.Settings.Content.Music
end

function CharInit()
	char = plr.Character
	torso = char:WaitForChild("HumanoidRootPart")
	if canmute then CreateButton() end
end

if plr.Character and plr.Character.Parent ~= nil then
	CharInit()
end
plr.CharacterAdded:connect(function()
	CharInit()
end)
