Skip to content
View STGamer24YT's full-sized avatar
  • 05:23 (UTC -04:00)
  • YouTube @STG24

Block or report STGamer24YT

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
STGamer24YT/README.md

About me

  • I use Luau to make Roblox games
  • I'm studying JavaScript
  • I usually check issues in geode-sdk/geode
  • I know how to use Batch, and I make the code unnecessarily ugly :trollface:

Module for playing sound in Roblox

PlaySound.lua
-- // important // --
local tweenservice = game:GetService("TweenService")
local audio = nil

-- // get the player that is calling the functions //
local plr = game:GetService("Players").LocalPlayer

-- // this music is stored in ReplicatedStorage //
local MainMusic = game:GetService("ReplicatedStorage").sound.Main:GetChildren()
local GameMusic = game:GetService("ReplicatedStorage").sound.Game:GetChildren()

-- // code to fade in and out audio //
local inTweenInfo = TweenInfo.new(
	1, Enum.EasingStyle.Sine, Enum.EasingDirection.In
)
local outTweenInfo = TweenInfo.new(
	0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out
)

local iTween = tweenservice:Create(audio, inTweenInfo, {Volume = 0.5})
local oTween = tweenservice:Create(audio, inTweenInfo, {Volume = 0})

-- // function used by play() //
local fadeAudio = function(scope)
	if scope == "in" then
		iTween:Play()
		return
	elseif scope == "out" then
		oTween:Play()
		task.wait(0.7)
		return
	else
		print("oops :trollface:")
		return
	end
end

-- // module // --
local func = {}

func.MainMusic = MainMusic
func.GameMusic = GameMusic

-- // play audio //
func.play = function(scope)
	if audio ~= nil then -- if audio exists, destroy it
		fadeAudio("out")
		audio:Destroy()
		print("stopped!")
	end
	
	local selectedmusic = {}
	
	if scope == func.MainMusic then 
		selectedmusic = MainMusic
	elseif scope == func.GameMusic then
		selectedmusic = GameMusic
	else
		return "Error! Invalid Scope !{ module.game or module.map }!"
	end
	
	local rnd = math.random(1, #selectedmusic)
	task.wait(.1)
	
	audio = selectedmusic[rnd]:Clone()
	audio.Parent = plr:FindFirstChild("SoundPlace")
	audio:Play()
	fadeAudio("in")
	print("played!")
end

return func

Pinned Loading

  1. geode-sdk/geode geode-sdk/geode Public

    The ultimate Geometry Dash modding framework

    C++ 784 135

  2. HJfod/BetterEdit HJfod/BetterEdit Public

    Makes the Geometry Dash Editor Better

    C++ 148 42