Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't I click a text button in a scrolling frame?

I am trying to make a morph inventory gui. But there is one problem, buttons in scrolling frame won't work.

Here is the code :


for i, v in pairs(script.Parent:GetChildren()) do
v.MouseButton1Click:Connect(function()
print("clicked")
end)
end


Once i click the button, it doesn't print "clicked"

the local script is a child of the scrolling frame. I have a spin system that gives players a character. After the spin, it will be directed to the inventory (scrolling frame).

Here is a snip of the code :


local function addChartoFrame(character)
local clone = template:Clone()
clone.Name = character.Name
clone.name.Text = character.Name
clone.Parent = frame

local newChar = character:Clone()
newChar.Parent = clone.ViewportFrame

local cam = Instance.new("Camera")
cam.CFrame = newChar.Head.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0,0,2.5)
cam.Parent = clone.ViewportFrame

clone.ViewportFrame.CurrentCamera = cam
end


The template in "template:Clone()" is a text button in the replicated storage

1 answer

✓ Accepted answer
for i, v in pairs(script.Parent:GetChildren()) do
	if v:IsA'TextButton' then -- because the script is inside the scrolling frame, it will error at the script because MouseButton1Click wont work on the script, you need to make sure its only getting the buttons
		v.MouseButton1Click:Connect(function()
			print("clicked")
		end)
	end
end

3 comments

0

Thx for the reply! I will try that.

0

I tried it but sadly, it didn't work :(

0

I fixed it! I added a childadded function before the for i,v . Thx for the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.