How do I make an audio slow when "MenuOpened" or "MenuClosed" is detected?

I have little to no knowledge of this and I couldn’t find anything else like this.
Here is the code I came up with through research:

local GuiService = game:GetService("GuiService")
local Player = game.Players.LocalPlayer
local gamemusic = game.Workspace["Five Nights at Candy's - Menu Theme"]

gamemusic.PlaybackSpeed = 1

GuiService.MenuOpened:Connect(function()
	game.gamemusic.PlaybackSpeed = 0
	print(Player.Name.." opened their menu.")
end)

GuiService.MenuClosed:Connect(function()
	game.gamemusic.PlaybackSpeed = 1
	print(Player.Name.." closed their menu.")
end)

It is in a LocalScript

What do you mean by slow?

charchar

As in the change the value PlaybackSpeed from 1 to 0 then back to 1.
1 when the menu is not opened or is closed
0 when the menu is open

Oh, do you mean tweening the pitch ?

This text will be blurred

1 Like
local TweenService = game:GetService("TweenService")
local GuiService = game:GetService("GuiService")
local Player = game.Players.LocalPlayer
local gamemusic = game.Workspace:FindFirstChild("Five Nights at Candy's - Menu Theme")

gamemusic.PlaybackSpeed = 1

GuiService.MenuOpened:Connect(function()
	TweenService.create(gamemusic, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {PlaybackSpeed = 0}):Play()
	print(Player.Name.." opened their menu.")
end)

GuiService.MenuClosed:Connect(function()
TweenService.create(gamemusic, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {PlaybackSpeed = 1}):Play()
	print(Player.Name.." closed their menu.")
end)

I wrote that on my phone, tell me if its not working

Yeah it’s not working, I’m trying to use PlaybackSpeed value since that’s a bit easier, no idea though.

This is a function that tweens the playback speed.

Take a moment to understand what it does, then write it yourself.

local TweenService = game:GetService("TweenService")

function setPlaybackSpeed(playbackSpeed꞉ number)
    local tween = TweenService꞉Create(
        gamemusic, 
        TweenInfo.new(1, Enum․EasingStyle․Linear), -- We use linear because it makes no sense to use Quad here
        {
            PlaybackSpeed = playbackSpeed
        }
    )
    tween꞉Play()
end

In your MenuOpened/MenuClosed handler, you can call this function:

function menuOpened()
    setPlaybackSpeed(0)
end

See TweenService:Create.

There is errors in your code, are they purposeful or accidental?

Mobile.

local TweenService = game:GetService("TweenService")

function setPlaybackSpeed(playbackSpeed: number)
    local tween = TweenService:Create(
        gamemusic, 
        TweenInfo.new(1, Enum.EasingStyle.Linear), -- We use linear because it makes no sense to use Quad here
        {
            PlaybackSpeed = playbackSpeed
        }
    )
    tween:Play()
end

Hmm no it still isn’t working
No errors either,
edit: i don’t think it’s evening detecting that I’m opening menu or it would’ve at least printed it

Did you call the function?

1 Like

Just to make sure, should this be in a LocalScript or a Script?

It should be in a LocalScript, since it deals with the client.

1 Like

I don’t believe there is a problem with your code, the code is just not detecting that the user is opening the menu.
and yes i did use your function

After looking at your previous screenshot, I’ve noticed that the script is in the Workspace.

Try moving it to StarterPlayerScripts.

See LocalScript.

Your answer was correct but you forgot to do :create instead of .create on line 14

here’s what you were helping me make


tysm for your help

1 Like