Button in scrolling frame not working for mobile

Here’s a video, what meant to happen is whenever i press the buttons it meant to play different music. Each button has different music. The music in the background is a default music that automatically plays when player joins
robloxapp-20200526-1808000.wmv (192.9 KB)

Works fine in PC
robloxapp-20200526-1816014.wmv (263.2 KB)

Could you show any of the code behind the scrolling frame? It’s hard to tell what’s wrong without seeing anything.

Sorry for late response but i didn’t get notified for some reason.
(I didn’t made this model Gui i got it from toolbox)

Screen shot of the Gui =

Script =
local tracks = {
{
id = 1837461008,
name = “N”
},
{
id = 1841905171,
name = “Na”
},
{
id = 1838660362,
name = “Nam”
},
{
id = 1837324424,
name = “e”
},
{
id = 1837848642,
name = “Nae”
},
{
id = 1839029458,
name = “ame”
}
}
local colors = {
Color3.new(1, 1, 1),
Color3.new(0, .64, 1),
Color3.new(1, .8, .2),
Color3.new(1, .3, 1),
Color3.new(0, 1, 0)
}

--------------

local runservice = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local plrgui = plr:WaitForChild("PlayerGui")
local scngui = plrgui:WaitForChild("[MP3]")
local mframe = scngui:WaitForChild("mainframe")
local play = mframe:WaitForChild("play")
local stop = mframe:WaitForChild("stop")
local nex = mframe:WaitForChild("next")
local rep = mframe:WaitForChild("repeat")
local prev = mframe:WaitForChild("prev")
local label = mframe:WaitForChild("label")
local name = mframe:WaitForChild("name")
local bar = mframe:WaitForChild("bar")
local progress = bar:WaitForChild("progress")
local line = bar:WaitForChild("line")
local libr = scngui:WaitForChild("library")
local add = libr:WaitForChild("add")
local shuffle = libr:WaitForChild("shuffle")
local color = libr:WaitForChild("color")
local newname = libr:WaitForChild("newname")
local newid = libr:WaitForChild("newid")
local scrframe = libr:WaitForChild("scrollingframe")
local sound = Instance.new("Sound", scngui)

local playing = false
local repeating = false
local shuffling = false
local lmb = false
local theme = 1
local track = 1

function createlibrary()
	scrframe:ClearAllChildren()
	local c = colors[theme] or Color3.new(1, 1, 1)
	local scroll = false
	scrframe.CanvasSize = UDim2.new(0, 0, 0, #tracks *30 -2)
	if scrframe.AbsoluteSize.Y < #tracks *30 -2 then
		scroll = true
	end
	local count = 0
	for i, v in pairs(tracks) do
		local name = v["name"]
		local image = v["image"]
		local b = Instance.new("TextButton")
		b.Name = i
		b.Text = ""
		b.Size = UDim2.new(1, 0, 0, 28)
		if scroll then
			b.Size = UDim2.new(1, -12, 0, 28)
		end
		b.Position = UDim2.new(0, 0, 0, count *30)
		b.BorderSizePixel = 0
		b.BackgroundTransparency = .5
		b.BackgroundColor3 = Color3.new(.122, .122, .122)
		local il = Instance.new("ImageLabel", b)
		il.Size = UDim2.new(1, 0, 1, 0)
		il.SizeConstraint = Enum.SizeConstraint.RelativeYY
		il.BackgroundTransparency = 1
		if image then
			il.Image = "rbxassetid://".. image
		else
			il.Image = "rbxassetid://363053247"
		end
		il.ImageColor3 = c
		local il2 = Instance.new("ImageButton", b)
		il2.Position = UDim2.new(1, -26, 0, 2)
		il2.Size = UDim2.new(0, 24, 0, 24)
		il2.SizeConstraint = Enum.SizeConstraint.RelativeYY
		il2.BackgroundTransparency = 1
		il2.ImageColor3 = c
		if track == i then
			il2.Image = "rbxassetid://363053392"
		else
			il2.Image = ""
		end
		local t
		if name then
			t = Instance.new("TextLabel", b)
			t.Text = name
			if track == i then
				t.Size = UDim2.new(1, -56, 1, 0)
			else
				t.Size = UDim2.new(1, -28, 1, 0)
			end
			t.Position = UDim2.new(0, 28, 0, 0)
			t.BackgroundTransparency = 1
			t.TextXAlignment = Enum.TextXAlignment.Left
			t.Font = Enum.Font.SourceSansLight
			t.FontSize = Enum.FontSize.Size18
			t.TextColor3 = c
			t.TextWrapped = true
		end
		il2.MouseButton1Click:connect(function()
			if i ~= track and #tracks > 1 then
				if track >= i then
					track = track -1
				end
				if track < 1 then
					track = 1
				end
				table.remove(tracks, i)
				createlibrary()
			end
		end)
		b.MouseButton1Click:connect(function()
			if i ~= track then
				sound:Stop()
			end
			track = i
			createlibrary()
			resume()
		end)
		b.MouseEnter:connect(function()
			if track ~= i and #tracks > 1 then
				il2.Position = UDim2.new(1, -28, 0, 0)
				il2.Size = UDim2.new(0, 28, 0, 28)
				il2.Image = "rbxassetid://363596208"
				if t then
					t.Size = UDim2.new(1, -56, 1, 0)
				end
			end
		end)
		b.MouseLeave:connect(function()
			il2.Position = UDim2.new(1, -26, 0, 2)
			il2.Size = UDim2.new(0, 24, 0, 24)
			if track == i then
				il2.Image = "rbxassetid://363053392"
			else
				il2.Image = ""
			end
			if t then
				if track == i then
					t.Size = UDim2.new(1, -56, 1, 0)
				else
					t.Size = UDim2.new(1, -28, 1, 0)
				end
			end
		end)
		b.Parent = scrframe
		count = count +1
	end
end

function changecolor()
	local c = colors[theme] or Color3.new(1, 1, 1)
	newname.TextColor3 = c
	newid.TextColor3 = c
	shuffle.ImageColor3 = c
	rep.ImageColor3 = c
	add.ImageColor3 = c
	play.ImageColor3 = c
	stop.ImageColor3 = c
	nex.ImageColor3 = c
	prev.ImageColor3 = c
	color.ImageColor3 = c
	label.ImageColor3 = c
	progress.BackgroundColor3 = c
	name.TextColor3 = c
	createlibrary()
end

function resume()
	local s = tracks[track]
	if s and s["id"] and tonumber(string.sub(sound.SoundId, 14)) ~= s.id then
		sound.SoundId = "rbxassetid://".. s.id
		sound:Play()
	end
	name.Text = ""
	if s["name"] then
		name.Text = s.name
	end
	sound:Resume()
	if s["image"] then
		label.image = "rbxassetid://".. s.image
	end
	play.Image = "rbxassetid://363053878"
	playing = true
end

color.MouseButton1Click:connect(function()
	local changed
	for i, v in pairs(colors) do
		if color.ImageColor3 == v then
			theme = i +1
			if theme > #colors then
				theme = 1
			end
			changecolor()
			changed = true
			break
		end
	end
	if not changed then
		changecolor(colors[1])
	end
end)

play.MouseButton1Click:connect(function()
	if not playing then
		resume()
	else
		sound:Pause()
		play.Image = "rbxassetid://363053392"
		playing = false
	end
end)

stop.MouseButton1Click:connect(function()
	if playing then
		sound:Stop()
		play.Image = "rbxassetid://363053392"
		playing = false
	end
end)

prev.MouseButton1Click:connect(function()
	track = track -1
	if track < 1 then
		track = #tracks
	end
	createlibrary()
	sound:Stop()
	resume()
end)

nex.MouseButton1Click:connect(function()
	track = track +1
	if track > #tracks then
		track = 1
	end
	createlibrary()
	sound:Stop()
	resume()
end)

rep.MouseButton1Click:connect(function()
	repeating = not repeating
	sound.Looped = repeating
	if repeating then
		rep.ImageTransparency = 0
	else
		rep.ImageTransparency = .75
	end
end)

shuffle.MouseButton1Click:connect(function()
	shuffling = not shuffling
	if shuffling then
		shuffle.Image = "rbxassetid://363552511"
	else
		shuffle.Image = "rbxassetid://363552398"
	end
end)

label.MouseButton1Click:connect(function()
	libr.Visible = not libr.Visible
end)

sound.Ended:connect(function()
	if not repeating then
		if shuffling and #tracks > 1 then
			local current = track
			repeat
				track = math.random(#tracks)
			until track ~= current
		else
			track = track +1
			if track > #tracks then
				track = 1
			end
		end
		createlibrary()
		sound:Stop()
		resume()
	end
end)

add.MouseButton1Click:connect(function()
	local d = tonumber(newid.Text)
	if d then
		table.insert(tracks, {id = d, name = newname.Text})
	end
	newid.Text = "id"
	newname.Text = "name"
	createlibrary()
end)

mouse.Button1Down:connect(function()
	lmb = true
end)

mouse.Button1Up:connect(function()
	lmb = false
end)

createlibrary()

runservice:BindToRenderStep("mp3player", 100, function()
	progress.Size = UDim2.new(sound.TimePosition /sound.TimeLength, 0, 1, 0)
	if mouse.X > bar.AbsolutePosition.X and mouse.X < bar.AbsolutePosition.X +bar.AbsoluteSize.X and
		mouse.Y > bar.AbsolutePosition.Y -bar.BorderSizePixel and mouse.Y < bar.AbsolutePosition.Y +bar.AbsoluteSize.Y +bar.BorderSizePixel then
		line.Size = UDim2.new(0, mouse.X -bar.AbsolutePosition.X, 1, 0)
		if lmb then
			local continue = sound.IsPlaying
			sound:Pause()
			sound.TimePosition = sound.TimeLength *(mouse.X -bar.AbsolutePosition.X) /bar.AbsoluteSize.X
			if continue then
				repeat
					wait()
				until not lmb
				sound:Resume()
			end
		end
	else
		line.Size = UDim2.new()
	end
end)

You should really wrap all that code with the “Preformatted Text” tags. This button " </> ". Sure would make it alot easier to read.

1 Like

Thanks for telling me i didn’t knew that

2 Likes

I’m looking through the code now. There is alot going on so it may take a little while to trace myself. What you could do for now is plug in some print statements along the code pathway to see how far its getting before it doesn’t work. Its the button actually registering a click? How far does it make it past that? Use print statements to figure that out. Are you getting any errors or are we dealing with a logical error?

Where is it not working? The code uses mouse click events. If your not using a mouse how will a mouse click ever fire an event?

I am new to coding. Will it be easier for you if i just send you the model?
if so here is it =

I see. Well what your going to want to do is “connect” those functions to touch events aswell. One easy way to do both is to simply fire an event off the Button itself.
So something along the lines of:

local myFunction()
    --Do something
end
myGUIBtn.InputBegan:Connect(myFunction)

Then when the user mouse clicks or touches the btn it will fire the event. If you look up the “TextButton” or “ImageButton” objects in the developer reference they say which events they have to use.

tbh I am not sure what to do really

Change the MouseButton1Click to InputBegan, like he showed.

i did still dont work (30 characters)

Maybe try to change it to Activated.

Inputbegan to activated? (30 characters)

Yeah. Also, make sure you have correct capitalization.

still dont work (30 characters)

Can I see the updated code?

local tracks = {
{
	id =  1837461008,
	name = "N"
},
{
	id = 1841905171,
	name = "Na"
},
{
	id = 1838660362,
	name = "Nam"
},
{
	id = 1837324424,
	name = "e"
},
{
	id = 1837848642,
	name = "Nae"
},
{
	id = 1839029458,
	name = "ame"
}

}
local colors = {
Color3.new(1, 1, 1),
Color3.new(0, .64, 1),
Color3.new(1, .8, .2),
Color3.new(1, .3, 1),
Color3.new(0, 1, 0)
}


local runservice = game:GetService(“RunService”)
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local plrgui = plr:WaitForChild(“PlayerGui”)
local scngui = plrgui:WaitForChild(“[MP3]”)
local mframe = scngui:WaitForChild(“mainframe”)
local play = mframe:WaitForChild(“play”)
local stop = mframe:WaitForChild(“stop”)
local nex = mframe:WaitForChild(“next”)
local rep = mframe:WaitForChild(“repeat”)
local prev = mframe:WaitForChild(“prev”)
local label = mframe:WaitForChild(“label”)
local name = mframe:WaitForChild(“name”)
local bar = mframe:WaitForChild(“bar”)
local progress = bar:WaitForChild(“progress”)
local line = bar:WaitForChild(“line”)
local libr = scngui:WaitForChild(“library”)
local add = libr:WaitForChild(“add”)
local shuffle = libr:WaitForChild(“shuffle”)
local color = libr:WaitForChild(“color”)
local newname = libr:WaitForChild(“newname”)
local newid = libr:WaitForChild(“newid”)
local scrframe = libr:WaitForChild(“scrollingframe”)
local sound = script.Parent.Sound

local playing = false
local repeating = false
local shuffling = false
local lmb = false
local theme = 1
local track = 1

function createlibrary()
scrframe:ClearAllChildren()
local c = colors[theme] or Color3.new(1, 1, 1)
local scroll = false
scrframe.CanvasSize = UDim2.new(0, 0, 0, #tracks *30 -2)
if scrframe.AbsoluteSize.Y < #tracks *30 -2 then
scroll = true
end
local count = 0
for i, v in pairs(tracks) do
local name = v[“name”]
local image = v[“image”]
local b = Instance.new(“TextButton”)
b.Name = i
b.Text = “”
b.Size = UDim2.new(1, 0, 0, 28)
if scroll then
b.Size = UDim2.new(1, -12, 0, 28)
end
b.Position = UDim2.new(0, 0, 0, count *30)
b.BorderSizePixel = 0
b.BackgroundTransparency = .5
b.BackgroundColor3 = Color3.new(.122, .122, .122)
local il = Instance.new(“ImageLabel”, b)
il.Size = UDim2.new(1, 0, 1, 0)
il.SizeConstraint = Enum.SizeConstraint.RelativeYY
il.BackgroundTransparency = 1
if image then
il.Image = “rbxassetid://”… image
else
il.Image = “rbxassetid://363053247”
end
il.ImageColor3 = c
local il2 = Instance.new(“ImageButton”, b)
il2.Position = UDim2.new(1, -26, 0, 2)
il2.Size = UDim2.new(0, 24, 0, 24)
il2.SizeConstraint = Enum.SizeConstraint.RelativeYY
il2.BackgroundTransparency = 1
il2.ImageColor3 = c
if track == i then
il2.Image = “rbxassetid://363053392”
else
il2.Image = “”
end
local t
if name then
t = Instance.new(“TextLabel”, b)
t.Text = name
if track == i then
t.Size = UDim2.new(1, -56, 1, 0)
else
t.Size = UDim2.new(1, -28, 1, 0)
end
t.Position = UDim2.new(0, 28, 0, 0)
t.BackgroundTransparency = 1
t.TextXAlignment = Enum.TextXAlignment.Left
t.Font = Enum.Font.SourceSansLight
t.FontSize = Enum.FontSize.Size18
t.TextColor3 = c
t.TextWrapped = true
end
il2.Activated:connect(function()
if i ~= track and #tracks > 1 then
if track >= i then
track = track -1
end
if track < 1 then
track = 1
end
table.remove(tracks, i)
createlibrary()
end
end)
b.Activated:connect(function()
if i ~= track then
sound:Stop()
end
track = i
createlibrary()
resume()
end)
b.MouseEnter:connect(function()
if track ~= i and #tracks > 1 then
il2.Position = UDim2.new(1, -28, 0, 0)
il2.Size = UDim2.new(0, 28, 0, 28)
il2.Image = “rbxassetid://363596208”
if t then
t.Size = UDim2.new(1, -56, 1, 0)
end
end
end)
b.MouseLeave:connect(function()
il2.Position = UDim2.new(1, -26, 0, 2)
il2.Size = UDim2.new(0, 24, 0, 24)
if track == i then
il2.Image = “rbxassetid://363053392”
else
il2.Image = “”
end
if t then
if track == i then
t.Size = UDim2.new(1, -56, 1, 0)
else
t.Size = UDim2.new(1, -28, 1, 0)
end
end
end)
b.Parent = scrframe
count = count +1
end
end

function changecolor()
local c = colors[theme] or Color3.new(1, 1, 1)
newname.TextColor3 = c
newid.TextColor3 = c
shuffle.ImageColor3 = c
rep.ImageColor3 = c
add.ImageColor3 = c
play.ImageColor3 = c
stop.ImageColor3 = c
nex.ImageColor3 = c
prev.ImageColor3 = c
color.ImageColor3 = c
label.ImageColor3 = c
progress.BackgroundColor3 = c
name.TextColor3 = c
createlibrary()
end

function resume()
local s = tracks[track]
if s and s[“id”] and tonumber(string.sub(sound.SoundId, 14)) ~= s.id then
sound.SoundId = “rbxassetid://”… s.id
sound:Play()
end
name.Text = “”
if s[“name”] then
name.Text = s.name
end
sound:Resume()
if s[“image”] then
label.image = “rbxassetid://”… s.image
end
play.Image = “rbxassetid://363053878”
playing = true
end

color.Activated:connect(function()
local changed
for i, v in pairs(colors) do
if color.ImageColor3 == v then
theme = i +1
if theme > #colors then
theme = 1
end
changecolor()
changed = true
break
end
end
if not changed then
changecolor(colors[1])
end
end)

play.Activated:connect(function()
if not playing then
resume()
else
sound:Pause()
play.Image = “rbxassetid://363053392”
playing = false
end
end)

stop.Activated:connect(function()
if playing then
sound:Stop()
play.Image = “rbxassetid://363053392”
playing = false
end
end)

prev.Activated:connect(function()
track = track -1
if track < 1 then
track = #tracks
end
createlibrary()
sound:Stop()
resume()
end)

nex.Activated:connect(function()
track = track +1
if track > #tracks then
track = 1
end
createlibrary()
sound:Stop()
resume()
end)

rep.Activated:connect(function()
repeating = not repeating
sound.Looped = repeating
if repeating then
rep.ImageTransparency = 0
else
rep.ImageTransparency = .75
end
end)

shuffle.Activated:connect(function()
shuffling = not shuffling
if shuffling then
shuffle.Image = “rbxassetid://363552511”
else
shuffle.Image = “rbxassetid://363552398”
end
end)

label.Activated:connect(function()
libr.Visible = not libr.Visible
end)

sound.Ended:connect(function()
if not repeating then
if shuffling and #tracks > 1 then
local current = track
repeat
track = math.random(#tracks)
until track ~= current
else
track = track +1
if track > #tracks then
track = 1
end
end
createlibrary()
sound:Stop()
resume()
end
end)

add.Activated:connect(function()
local d = tonumber(newid.Text)
if d then
table.insert(tracks, {id = d, name = newname.Text})
end
newid.Text = “id”
newname.Text = “name”
createlibrary()
end)

mouse.Button1Down:connect(function()
lmb = true
end)

mouse.Button1Up:connect(function()
lmb = false
end)

createlibrary()

runservice:BindToRenderStep(“mp3player”, 100, function()
progress.Size = UDim2.new(sound.TimePosition /sound.TimeLength, 0, 1, 0)
if mouse.X > bar.AbsolutePosition.X and mouse.X < bar.AbsolutePosition.X +bar.AbsoluteSize.X and
mouse.Y > bar.AbsolutePosition.Y -bar.BorderSizePixel and mouse.Y < bar.AbsolutePosition.Y +bar.AbsoluteSize.Y +bar.BorderSizePixel then
line.Size = UDim2.new(0, mouse.X -bar.AbsolutePosition.X, 1, 0)
if lmb then
local continue = sound.IsPlaying
sound:Pause()
sound.TimePosition = sound.TimeLength *(mouse.X -bar.AbsolutePosition.X) /bar.AbsoluteSize.X
if continue then
repeat
wait()
until not lmb
sound:Resume()
end
end
else
line.Size = UDim2.new()
end
end)

Hm… :thinking: Maybe try MouseButton1Down

3 Likes

Omg finally it worked thank you so much!
robloxapp-20200527-1311241.wmv (153.8 KB)