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

Sound just randomly doesn't play?

Asked by 2 years ago
Edited 2 years ago

I am working on a random music player that plays when the game loads but for some reason the song id just gets set to blank after the script is run, I confirmed this by setting the soundid manually to one of them and once the script is loaded the music stops running

if script.Parent.Parent == game.ReplicatedFirst then -- Checks if it's in replicated first and if so will move to PlayerGui
    local clone = script.Parent:Clone()
    clone.Parent = game.Players.LocalPlayer.PlayerGui 
    script.Parent:Destroy()
end



local music = {5409360995,1845554017,9048045656,9044564552} -- Setting up variables and arrays
local sound = script.Sound
local mute = script.Parent.Frame.Mute
local playpause = script.Parent.Frame.PlayPause
local skip = script.Parent.Frame.Skip
local gen = 0
local mutedvar = script.IsMuted
local playingvar = script.IsPlaying
local song = 1

mutedvar.Value = 0 -- Setting Values
sound.Playing = true

table.sort(music, function() -- Shuffles Music
    return Random.new():NextNumber() < 0.5
end)

function sortmusic() -- Shuffle Music Function
    table.sort(music, function()
        return Random.new():NextNumber() < 0.5
    end)
end

while true do -- Button Checking Script
    wait()

    if mute.MouseButton1Click then
        if mutedvar.value == 0 then
            sound.Volume = 0
            mutedvar.Value = 1
        end

    else
        sound.Volume = 0.5
        mutedvar.Value = 0

    end

    if playpause.MouseButton1Click then

    end

    if skip.MouseButton1Click then

    end

end

while true do -- Music Player Script
    sound.Playing = true
    sound.IsPlaying = true
    sound.SoundId = ("rbxassetid://" + music[song])
    song +=1
    repeat wait() until sound.IsPlaying == false
    if #music == song then
        sortmusic()
    end
end
0
uhhhhhhhhhh too long? dradsds 0 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

I don’t see the :Play() function in the script, so that might be the solution. Just try sound:Play() instead of sound.Playing = true or sound.IsPlaying = true, since the properties you are changing only indicate that they are playing and they don’t actually play them.

This might be helpful:

https://developer.roblox.com/en-us/api-reference/function/Sound/Play

0
Thanks! User#39520 0 — 2y
Ad

Answer this question