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

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

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)
                                      

1 comment

0

you just need to make local variables

1 answer

✓ Accepted answer

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

3 comments

0

The box is the frame where the players buy the items. And yes the script is a local script

0

Also I got another error saying: "MouseClick is not a valid member of ScreenGui"

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

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