I have this sound ID Player that you type a sound ID into. there are two buttons, one that alternates from a play button and a pause button (depending on whether the song is playing or not), and a button to loop the song.
This first script is for the Sound ID's. when a sound ID is typed into the box and a player presses enter, the button which controls the playback switches it's image to a pause button.
local MusicIDBox = script.Parent.Parent.MusicIDBox
local PausePlayButton = script.Parent.Parent.Parent.Frame.PausePlayButton
local NowPlaying = script.Parent.Parent.Parent.Frame.NowPlaying
local Sound = game.workspace:WaitForChild("Sound")
local function changeSong(enterPressed)
if enterPressed then
Sound:Play()
PausePlayButton.Image = "http://www.roblox.com/asset/?id=293466203"
Sound.SoundId = "rbxassetid://"..MusicIDBox.Text
end
end
local function changeTitle(enterPressed)
if enterPressed then
NowPlaying.Text = "Now Playing: " .. game:GetService("MarketplaceService"):getProductInfo(tonumber(MusicIDBox.Text)).Name
end
end
MusicIDBox.FocusLost:Connect(changeSong)
MusicIDBox.FocusLost:Connect(changeTitle)
When I try to click on the pause button for the first time after entering a Sound ID, the song does not pause when I click on the button, and the buttons image does not change to a play button. But when I click it again, it functions normally.
local IsLooping = script.Parent.Parent.Parent.Frame.IsLooping
local PausePlayButton = script.Parent.Parent.Parent.Frame.PausePlayButton
local LoopButton = script.Parent.Parent.Parent.Frame.LoopButton
local Sound = game.workspace:WaitForChild("Sound")
local Frame = script.Parent.Parent.Parent.Frame
local function playbackControl()
if Sound.IsPlaying == true then
Sound:Pause()
PausePlayButton.Image = "http://www.roblox.com/asset/?id=293466205"
else
Sound:Play()
PausePlayButton.Image = "http://www.roblox.com/asset/?id=293466203"
end
end
local function loopSong()
if Sound.Looped == false then
Sound.Looped = true
IsLooping.Text = "Looping: ON"
else if Sound.Looped == true then
Sound.Looped = false
IsLooping.Text = "Looping: OFF"
end
end
end
-- pause button: = http://www.roblox.com/asset/?id=293466203
-- play button: http://www.roblox.com/asset/?id=293466205
-- stop button http://www.roblox.com/asset/?id=293466207
-- loop button http://www.roblox.com/asset/?id=588808350
PausePlayButton.MouseButton1Click:Connect(playbackControl)
LoopButton.MouseButton1Click:Connect(loopSong)

1 comment
for line 8 try if Sound.Playing == true then also i normally find it safer to not connect functions but just to make a function straight like PausePlayButton.MouseButton1Click:connect(function()