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

Sound is failing to play when clicked?

Asked by 6 years ago
Edited 6 years ago

Hello,

I've made a custom music player for my game, and it worked when I was creating a "new" music player every time a song image was clicked, but when I condensed it down to one player, where the SoundId would change every time a new song image was selected, it stopped playing music. I was getting the "sound failed to load" errors, then I saw that last year there were changes made to how SoundIds are pre-loaded, so I made some adjustments, but still no song playing. The Text changes for the selected song, but no sound. No errors either.

How do I fix this?

I cut out the unnecessary portions of my script and included the relevant part below:

local ContentProvider = game:GetService("ContentProvider")

local SongID00 = "rbxassetid://909515912"
local SongID01 = "rbxassetid://287091285"
local SongID02 = "rbxassetid://224912151"

local sound00 = Instance.new("Sound")
sound00.SoundId = SongID00
local sound01 = Instance.new("Sound")
sound01.SoundId = SongID01
local sound02 = Instance.new("Sound")
sound02.SoundId = SongID02

local assets = {sound00, sound01, sound02 }

ContentProvider:PreloadAsync(assets)
print("All assets loaded.")
wait(1)

--//Get Services
local RS = game:GetService("ReplicatedStorage")
--//String Values in RepStorage
local MusicPlayerSongIDValue = RS:WaitForChild("MusicPlayerSongIDValue")
local MusicPlayerTrackIDValue = RS:WaitForChild("MusicPlayerTrackIDValue")
MusicPlayerSongIDValue.Value = SongID00

--//MUSIC BOX
local MusicBoxSound = MUSICSBOX.Sound
local TrackPlaying = MUSICSBOX.TrackPlaying
TrackPlaying.Text = ''

MUSICPLAYERButton.MouseButton1Click:Connect(function()

local MusicBoxSound = MUSICSBOX.Sound
MusicBoxSound.SoundId = "http://www.roblox.com/asset/?id="..MusicPlayerSongIDValue.Value
local MusicBoxPlayButton = MUSICSBOX.PLAYButton
local MusicBoxStopButton = MUSICSBOX.STOPButton
local MusicBoxPauseButton = MUSICSBOX.PAUSEButton
local MusicBoxResumeButton = MUSICSBOX.RESUMEButton

TrackPlaying.Text = 'TRACK ' ..MusicPlayerTrackIDValue.Value..' SELECTED'

MusicBoxPlayButton.MouseButton1Click:Connect(function()
MusicBoxSound:Play()
MusicBoxPauseButton.Visible = true
MusicBoxResumeButton.Visible = false
TrackPlaying.Text = 'TRACK PLAYING: ' ..MusicPlayerTrackIDValue.Value..''
end)

MusicBoxPauseButton.MouseButton1Click:Connect(function()
MusicBoxSound:Pause()
MusicBoxPauseButton.Visible = false
MusicBoxResumeButton.Visible = true
TrackPlaying.Text = 'TRACK ' ..MusicPlayerTrackIDValue.Value..' PAUSED'
end)

MusicBoxResumeButton.MouseButton1Click:Connect(function()
MusicBoxSound:Resume()
MusicBoxPauseButton.Visible = true
MusicBoxResumeButton.Visible = false
TrackPlaying.Text = 'TRACK PLAYING: ' ..MusicPlayerTrackIDValue.Value..''
end)

MusicBoxStopButton.MouseButton1Click:Connect(function()
MusicBoxSound:Stop()
MusicBoxPauseButton.Visible = true
MusicBoxResumeButton.Visible = false
MusicPlayerTrackIDValue.Value = 00
TrackPlaying.Text = ''
end)

Song01.MouseButton1Click:Connect(function()
MusicPlayerSongIDValue.Value = SongID01
MusicPlayerTrackIDValue.Value = '01'
end)

Song02.MouseButton1Click:Connect(function()
MusicPlayerSongIDValue.Value = SongID02
MusicPlayerTrackIDValue.Value = '02'
end)


end)--closes music player

Thank you!

1 answer

Log in to vote
0
Answered by 6 years ago

I solved my problem. :) I forgot to include a Changed local script on the Sound file itself:

local RS = game:GetService('ReplicatedStorage')
local MusicPlayerSongIDValue = RS:WaitForChild("MusicPlayerSongIDValue")

script.Parent.SoundId = MusicPlayerSongIDValue.Value
MusicPlayerSongIDValue.Changed:connect(function()
script.Parent.SoundId = MusicPlayerSongIDValue.Value
end)
Ad

Answer this question