Problem with Click Detector

Hello, developer forum!

I’m having a problem with my click detector and it’s outputting an error that seems to not be related to the line of code at all.

My Code:

local P1A = game.Workspace.Part1A

local P1B = game.Workspace.Part1Button

local CD1 = game.Workspace.Part1Button.CD

CD1.MouseClick:Connect(function()

P1A.Position = {-8, 0.5, 18}

end)

The Error:

Workspace.Part1Button.Script:6: invalid argument #3 (Vector3 expected, got table) - Server - Script:6

All help is appreciated!

(I’m generally new to scripting too)

That’s not how you give a Vector3

P1A.Position = {-8, 0.5, 18}

Should be

P1A.Position = Vector3.new(-8, 0.5, 18)

Position accepts Vector3, not a table

Thank you very much! As I said, I’m pretty new to scripting, so very much appreciated!

you need to use Vector3.new

P1A.Position = Vector3.new(-8,0.5,18)

Also to add on a bit to what I said, you made a variable for game.Workspace.Part1Button yet to don’t use it, to help out a bit

local CD1 = game.Workspace.Part1Button.CD

Should be

local CD1 = P1B.CB

So you are using your P1B variable

Also, use workspace instead of game.Workspace as they both do the same thing but workspace is shorter and references the Workspace service directly in the event you accidentally rename the service in the Explorer.

If you have anymore issues don’t be afraid to make another post!

Alright, thanks for the useful information!

1 Like