Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I pause music and how do I put a max on the volume?

Hello scripters,

So I got a localscript going on where you play music when you pressed like 'Play' in the game. But how do I pause the song? Also I want the volume to go from 1 to 2, how do I put a minimum on 1 and a maximum on 2? I think I should use an if statement but im not sure.

local plus = script.Parent:FindFirstChild("Plus")
local off = script.Parent:FindFirstChild("Off")
local minus = script.Parent:FindFirstChild("Minus")
local sound = game.SoundService:FindFirstChild("WaitingLobby")

if 

Kind Regards

3 answers

✓ Accepted answer
-- Local Script
local plus = script.Parent:WaitForChild("Plus")
local off = script.Parent:WaitForChild"Off")
local minus = script.Parent:WaitForChild("Minus")
local sound = game.SoundService:WaitForChild("WaitingLobby")
sound.Volume = 1

plus.MouseButton1Click:Connect(function()
	if sound.Volume >=1 then
		sound.Volume = sound.Volume + 0.25
	end
	if sound.Volume > 2 then
		sound.Volume = 2
	end
end)

minus.MouseButton1Click:Connect(function()
	if sound.Volume >=1 then
		sound.Volume = sound.Volume - 0.25
	end
	if sound.Volume > 2 then
		sound.Volume = 2
	end
	if sound.Volume < 1 then
		sound.Volume = 1
	end
end)

enabled = true
off.MouseButton1Click:Connect(function()
	if enabled == true then
	enabled = false
		sound:Pause()
		off.Text = "On"
	else
	enabled = true
	sound:Resume()
	off.Text = "Off"
end
end)

There, haven't been tested it but I hope that It'll work! In case that it doesn't work then say me.

EDIT: Added ("") on lines 34 and 38.

For pausing you just use Pause() like this sound:Pause(), then for resuming the sound just do sound:Resume()

also for this min and max thing obviously just use an if statement to check if it's going lower than 1 then just set it to 1, same thing with max.

Thanks man , this helped! Don't forget to put On at line 34 and off at line 38 in (""), But next to that thank you very much! This script you made will made me understand this so I can use this feature more often!

Kind Regards

1 comment

0

Glad to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.