Ad
Log in to vote
0

Attempt to index number with 'MouseButton1Click' can someone help me with this error?

Asked by 4 days ago
Edited 4 days ago

I'm making a shop GUI so players can buy swords and weapons. But an error appeared on the output saying "attempt to index number with 'MouseButton1Click'". and I tried everything that I could think of to fix this and it still doesn't work. I've tried finding online solutions but nothing helped. So I came here. Here's where I got the error:

         box.MouseButton1Click:Connect(function()--Where I got the error
    for _, v in pairs(itemViewport:GetChildren()) do
        if not v:IsA("Frame") then
            v:Destroy()
        end
    end
end)
0
you just need to make local variables Odoscementas 0 — 4d

1 answer

Log in to vote
0
Answered by 4 days ago

What is box? you need to tell what the box is like is it a script.parent or script.parent.parent.box you might need to put the script as a local script and/or put the script inside the GUI Is it a part? if it's a part then you need to do

script.Parent.MouseClick:Connect(function()
    for _, v in pairs(itemViewport:GetChildren()) do
            if not v:IsA("Frame") then
            v:Destroy()  
        end
     end
end)

you need to put it in the local script in the part

0
The box is the frame where the players buy the items. And yes the script is a local script Altbotnot 0 — 3d
0
Also I got another error saying: "MouseClick is not a valid member of ScreenGui" Altbotnot 0 — 3d
Ad

Answer this question