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)
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:
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