Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Audio is not playing when I call it?

Asked by
saucyP 7
7 years ago
Edited 7 years ago

I made a script where different music will play according to what is going on with the game. It's a LocalScriptin the StarterPlayerScripts, and the music folder is in ReplicatedStorage. However, the music doesn't play and there is no output error. Here's the code:

RoundRunning = game.ServerStorage.IsRoundRunning.Value
Inter = game.ServerStorage.Intermission.Value

--[[Song Variables]]--
local songs = game.ReplicatedStorage["Action Game Playlist"]
local battlefield = songs.SSBBBattlefield
local gourmet = songs.SSBBGourmetRace
local dedede = songs.SSBBKingDedede
local storm = songs.SSBBSongOfStorms
local tabuu = songs.SSBBVsTabuu
local tf2 = songs.TF2IntruderAlert
local patch = songs.MrPatch
local billy = songs.ChillyBilly
local temple = songs.Temple
local playlist = {battlefield, gourmet, dedede, storm, tabuu, tf2, patch, billy, temple}

--[[Functions]]--

function playSong()
    print("playing")
    local i = math.random(1, #playlist)
    local currentSong = playlist[i]
    currentSong:Play'' 
    currentSong.Looped = true
end

function stopSong()
    print("stopped")
    battlefield:Stop''
    gourmet:Stop''
    dedede:Stop''
    storm:Stop''
    tabuu:Stop''
    tf2:Stop''
    patch:Stop''
    billy:Stop''
    temple:Stop''
end


--[[Call the functions]]--

game.ServerStorage.Intermission.Changed:connect(function()
    if Inter == true then
    print("intermission is running")
    stopSong()
    end
end)

game.ServerStorage.IsRoundRunning.Changed:connect(function()
    if RoundRunning == true then
    print("round true")
    playSong()
    end
end)

0
ServerStorage can only be accessed by server scripts. Use ReplicatedStorage for local scripts to be able to access it. Perci1 4988 — 7y
0
I changed all the game.ServerStorage to game.ReplicatedStorage, however it still doesn't work. saucyP 7 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

First, change your function calls to use () instead of ''. Your way is technically functional, but makes the code a little weird to read.

Second, when you set RoundRunning = game.ServerStorage.IsRoundRunning.Value and Inter = game.ServerStorage.Intermission.Value, those variables RoundRunning and Inter will not change with the Values of IsRoundRunning and Intermission. They are set once and forgotten.

Actually, the Changed event passes the value of the thing changing. So while you could say things like Inter = game.Storage.Intermission; if (Inter.Value) then, you could instead remove your first two lines and make your functions look like:

game.ServerStorage.Intermission.Changed:connect(function(intermission)
    if (intermission) then
        print("intermission is running")
        stopSong()
    end
end)

game.ServerStorage.IsRoundRunning.Changed:connect(function(roundRunning)
    if (roundRunning) then
        print("round true")
        playSong()
    end
end)
0
Thanks a lot! The script runs perfectly now. saucyP 7 — 7y
Ad

Answer this question