--mute button stuff

local canmute = settings.DisplayMuteButton
local clonegui
if canmute then
	clonegui = script.MuteButtonGui:clone()
end
script.MuteButtonGui:Destroy()

local musicon = true

function SetButtonStyle(button)
	button.Text = "Music: ".. (musicon and "ON" or "OFF")
	button.Style = musicon and Enum.ButtonStyle.RobloxRoundDefaultButton or Enum.ButtonStyle.RobloxRoundDropdownButton
	button.TextColor3 = musicon and Color3.new(1,1,1) or Color3.new(.2,.2,.23)
end

function CreateButton()
	local gui = clonegui:clone()
	local button = gui.Button
	button.Visible = true
	SetButtonStyle(button)
	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
		SetButtonStyle(button)
	end)
	gui.Parent = plr:WaitForChild("PlayerGui")
end

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

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