UDim2 expected got Vector3

Hello,

I am getting an error “ReplicatedStorage.Framework.Client.Reticle:34: invalid argument #2 (UDim2 expected, got Vector3)”

I am following this DevForum post for a reticle module and I’m getting an error for the LookVector. I am doing part.CFrame.LookVector but it saying it needs a UDim2.

This is the code

			local projecterSight = sightModel:FindFirstChild("ProjectorSight")
			local surfaceGui = projecterSight:FindFirstChildWhichIsA("SurfaceGui")
			local clippingFrame = surfaceGui:FindFirstChild("ClippingFrame")
			local reticle = clippingFrame:FindFirstChild("Reticle")
			Library.Reticle:new(camera,0,reticle,clippingFrame)
			coroutine.wrap(function()
				task.wait(.2)
				reticleConnection = Library.RunService.RenderStepped:Connect(function()
					if not Modules.IsEquipped then
						reticleConnection:Disconnect()
					end
					Library.Reticle:Update(shootPart.CFrame.LookVector)
				end)
			end)()

And this is the reticle script

function Reticle:Update(lookVector)
	if not lookVector then return end
	local unitRay = self.Cam:ScreenPointToRay(self.Cam.ViewportSize.x/2, self.Cam.ViewportSize.y/2)
	local Result = workspace:Raycast(unitRay.Origin,(self.Surface.Position+lookVector*self.ZeroDistance)-unitRay.Origin,self.RayParams)
	if Result then
		if self.Decal.Visible ==  false then
			self.Decal.Visible = true
    	end
		
		local VectorPos = WorldToSurface(Result.Position,self.Surface,self.Surface.SurfaceGui.PixelsPerStud)
		
		self.Decal.Position = UDim2.new(0.5,-VectorPos.X*2*(10/self.Surface.Size.X),0.5,-VectorPos.Y*2*(10/self.Surface.Size.Y))
	else
		self.Decal.Visible = false
	end
end
2 Likes

Could you specify which line is line 34 as shown in the error?

1 Like

local Result = workspace:Raycast(unitRay.Origin,(self.Surface.Position+lookVector*self.ZeroDistance)-unitRay.Origin,self.RayParams)

I resolved the issue.

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

That’s great, I didn’t even have time to read the entire code, feel free to share the answer to the problem for potential visitors :+1:

(self.Surface.Position+lookVector*self.ZeroDistance)-unitRay.Origin

This calculation returns a Vector 3, so there is the problem but not knowing what the purpose of your Raycast is I cannot say what it should be replaced by.

I was supposed to give it an instance and instead I gave it a SurfaceGUI. I just misunderstood it.

A SurfaceGUI inherits from an instance.
It’s almost the same.

The problem here is probably that you provided him with a 3D Instance whose position is represented by a Vector3 while he wants an interface element whose position is represented by a UDim2.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.