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

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago
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
0
Thx for the reply! I will try that. XObbyCreatorX 38 — 2y
0
I tried it but sadly, it didn't work :( XObbyCreatorX 38 — 2y
0
I fixed it! I added a childadded function before the for i,v . Thx for the help! XObbyCreatorX 38 — 2y
Ad

Answer this question