local sO = script.Parent.Parent.SoundO
local s1 = workspace.Sound1
s1:Play()
function mouseClick1()
sP.Visible = false
sP.ZIndex = 0
sO.Visible = true
sO.ZIndex = 1
s1.Volume = 0
end
function mouseClick2()
sO.Visible = false
sO.ZIndex = 0
sP.Visible = true
sP.ZIndex = 1
s1.Volume = 0.1
end
sP.MouseButton1Click:Connect(mouseClick1)
sO.MouseButton1Click:Connect(mouseClick2)
I feel like there is a more effective way of doing this instead of the way I did. Would someone mind helping me with how I could’ve written this simple script better?
1 Like
From what I’m seeing why bother with two buttons? You could either use the value of a button or a tracking boolean to control the toggle:
local mute = false -- Tracking variable for ease of reading
local sound = workspace.Sound1 -- Path to the sound.
local muteBtn = script.Parent.Parent.Sound0 -- Whatever path to the button.
muteBtn.MouseButton1Click:Connect(function()
mute = not mute
if mute then
sound.Volume = 0
muteBtn.Text = "Unmute"
else
sound.Volume = 0.1
muteBtn.Text = "Mute"
end
end)
Keep in mind I tossed this example together. Not saying it’s the most polished but this is the concept of a simple toggle button.
3 Likes