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

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

Asked by 2 years ago
Edited 2 years 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 — 2y

1 answer

Log in to vote
0
Answered by 2 years 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 9 — 2y
0
Also I got another error saying: "MouseClick is not a valid member of ScreenGui" Altbotnot 9 — 2y
0
Oh wait, I didn't know that I placed this code in the wrong place lol I need glasses. Sorry for ignoring you I didn't notice. Thank you for your help Altbotnot 9 — 2y
Ad

Answer this question