GUI Collision script not working correctly

Hello everyone!
Im making a 2D engine for my game.
This script works… but since it uses AbsoluteSize and AbsolutePosition, it sees the hitbox as way bigger then it actually should be. When the instance “bullet” hits the “enemy” it should delete the enemy. However, there is no way to miss because the hitbox is so big. Any help? :tongue:

		bullet:GetPropertyChangedSignal("Position"):Connect(function() -- checks for pos changing
			local hitbox = bullet
			local pos1, size1 = enemy.AbsolutePosition, enemy.AbsoluteSize;
			local pos2, size2 = hitbox.AbsolutePosition, hitbox.AbsoluteSize;

			local top = (pos1.Y) - (pos2.Y)
			local bottom = (pos2.Y) - (pos1.Y)
			local left = (pos1.X) - (pos2.X)
			local right =(pos2.X) - (pos1.X)
			local touching = false

			if top < (size1.Y) and bottom < (size1.Y) and left < (size1.X) and right < (size1.X) then
				bullet:Destroy()
				enemy:Destroy()
			end

			return touching
		end)

Have you tried using hitbox.AbsoluteSize * 0.5

I will try that soon. Thank you

Same result sadly. No matter how long or how tall it is, it will always be 4x4 hitboxes

Can you try putting the comparisons in the if statement so each part and the whole comparison is surrounded by brackets like
if ((a>b) and (b>c)) then

Sorry for the delay, lol.

Can you give a example of this, as I have no idea what your describing

to

if ((top < (size1.Y)) and (bottom < (size1.Y)) and (left < (size1.X)) and (right < (size1.X))) then

This means that each comparison is inside a bracket pair so you are check for 4 comparisons all returning true.

Same result. Heres my code (output is clear)

		bullet:GetPropertyChangedSignal("Position"):Connect(function() -- checks for pos changing
			local hitbox = bullet
			local pos1, size1 = enemy.AbsolutePosition, enemy.AbsoluteSize;
			local pos2, size2 = hitbox.AbsolutePosition, hitbox.AbsoluteSize*0.5;

			local top = (pos1.Y) - (pos2.Y)
			local bottom = (pos2.Y) - (pos1.Y)
			local left = (pos1.X) - (pos2.X)
			local right =(pos2.X) - (pos1.X)
			local touching = false

			if ((top < (size1.Y)) and (bottom < (size1.Y)) and (left < (size1.X)) and (right < (size1.X))) then
				bullet:Destroy()
				enemy:Destroy()
			end

			return touching
		end)

Can you please print the values of the variables used in the if.