Changing sound volume by clicking on the button

  1. What do you want to achieve?
    Change Sound Volume by clicking on the button.
  2. What is the issue?

:Statement spans multiple lines use indentation to silence
Local script located in Starter Gui:

local player = game.Players.LocalPlayer
local Sound = game.Workspace.Sound
local Text = script.Parent:WaitForChild("TextLabel")
local Button = script.Parent

function onClick()
	if Sound.Volume == 0.4 then
	Sound.Volume = 0
	Text.Text = "Off"
	Text.TextColor3 = Color3.fromRGB(255, 51, 0)
	elseif
	Sound.Volume == 0 then
	Sound.Volume = 0.4
	end
end

Button.MouseButton1Click:Connect(onClick)

Any help appreciated.

1 Like

Your code is fine. The editor is just telling you that it may be hard to read your code because the expression is spanning multiple lines.

To fix that, just do elseif Sound.Volume == 0 then all on the same line.

1 Like

As @megukoo sayed, you only need to change this line:

Sound.Volume == 0 then

To:

elseif Sound.Volume == 0 then

That’s the script at the end:

local player = game.Players.LocalPlayer
local Sound = game.Workspace.Sound
local Text = script.Parent:WaitForChild("TextLabel")
local Button = script.Parent

function onClick()
	if Sound.Volume == 0.4 then
	Sound.Volume = 0
	Text.Text = "Off"
	Text.TextColor3 = Color3.fromRGB(255, 51, 0)
	elseif Sound.Volume == 0 then
	Sound.Volume = 0.4
	end
end

Button.MouseButton1Click:Connect(onClick)
1 Like

Thank you both it worked. @megukoo @leo007er1