invalid argument #2 (UDim2 expected, got Vector3) appears when i say
local MAX_DISTANCE = 2000
return (Target.Position - radar.Position).Magnitude <= MAX_DISTANCE
Where is my problem ???
What should i do ?
invalid argument #2 (UDim2 expected, got Vector3) appears when i say
local MAX_DISTANCE = 2000
return (Target.Position - radar.Position).Magnitude <= MAX_DISTANCE
Where is my problem ???
What should i do ?
i think ur trying to subtract and 2 different type of data, u cant find magnitude between a udim2 and vector3 (atleast as far as i know)
The error message you’re receiving indicates that the code is expecting a UDim2
value as the second argument but is receiving a Vector3
value instead. This suggests that either Target.Position
or radar.Position
is not of the correct data type.
The .Position
property of a Roblox instance returns a Vector3
value representing the 3D position of the instance in the game world. However, the distance calculation requires a UDim2
value representing the 2D position of the instance relative to its parent.
To fix the error, you can convert the Vector3
values to UDim2
values using the WorldToViewportPoint
method provided by the Workspace
service. Here’s an example of how you could modify your code:
local MAX_DISTANCE = 2000
local targetScreenPos = workspace.CurrentCamera:WorldToViewportPoint(Target.Position)
local radarScreenPos = workspace.CurrentCamera:WorldToViewportPoint(radar.Position)
local distance = (targetScreenPos - radarScreenPos).Magnitude
return distance <= MAX_DISTANCE`
In this code, we first use the WorldToViewportPoint method to convert the Vector3 positions of the target and the radar into Vector2 values representing their positions on the screen. We then calculate the distance between these two points using the .Magnitude property of the resulting Vector2. Finally, we compare the distance to MAX_DISTANCE and return true or false depending on the result.
this is nice information right here, i learned new stuff
i’ve had many errors like this that’s why i know so much about it.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.