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

Vector2 comparing error? attempt to compare Vector2

Trying to compare Vector2 values to detect if guis collide. The reason why I cannot just do == is because it will not be exactly the amount. Here is my function:

function checkPosition(gui1, gui2) 
	local gui1_topLeft = gui1.AbsolutePosition
	local gui2_topLeft = gui2.AbsolutePosition
	
	local math1 = Vector2.new(gui2.AbsoluteSize.X/2)
	local math2 = Vector2.new(gui1.AbsoluteSize.X/2)
	
	return (gui2_topLeft + math1 < gui1_topLeft - math2)
end

What is your thoughts? Is there something I am missing? Should I use something that is not Vector2? Let me know if you have any questions! Thanks, Jail.

1 answer

For Vector2, you do not have another comma.

As you can see in the code, the Vector2's don't have commas.

Errors:

local math1 = Vector2.new(gui2.AbsoluteSize.X/2)
local math2 = Vector2.new(gui1.AbsoluteSize.X/2)

Where it finishes the gui#.AbsoluteSize.X/2, you don't have a second comma

What it should look like:

local math1 = gui2.AbsoluteSize.X/2
local math2 = gui1.AbsoluteSize.X/2

Hope this helps you ;)

4 comments

0

There is an issue here, instead, it results with this error: invalid argument #2 (Vector2 expected, got number) Got any suggestions?

0

Hmm...

0

I dont really have any thing...

0

Should you add a If statement to detect if its there?

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