I thought variables could only have one name but in a few tutorials I have watched they have used two names in their variables such as hit, position = or success, error message =
Why does some variables have two names such as hit, position = --?--
2 answers
Sometimes, there can be more values returned from one event/function.
In this example, the FindPartOnRayWithIgnoreList returns the Target and the Position of the ray.
function GetMousePoint(X, Y)
local RayMag1 = Camera:ScreenPointToRay(X, Y) --Hence the var name, the magnitude of this is 1.
local NewRay = Ray.new(RayMag1.Origin, RayMag1.Direction * 2500)
local Target, Position = workspace:FindPartOnRayWithIgnoreList(NewRay, {Player.Character, workspace.FlyingSpells})
return {Target, Position}
end
2 comments
Return values, not parameters. A parameter is what a function takes in.
Yeah, my bad, I'll edit it rn.
This is because the function the variable has been assigned to returns 2 things instead of one. This isn't so much as the variable having 2 names as it is there are just two variables. Variables can be assigned to the same line like so
local Bob, Job = 5,3
print(Bob, Job) -- 5, 3
But what I think you're not getting is how can there be 2 variables when there's only one function.
local Bob, Job = 5
print(Bob, Job) -- 5, nil
Well it's because that function has returned 2 parameters back. Return can be said what the function will give you back if you store it as a variable (aka. return back).
local function BobsJob()
return 5,3
end
local Bob, Job = BobsJob()
print(Bob, Job) -- 5, 3
For your ray example with it returning hit, position, workspace:FindPartOnRay() actually returns 4 things being the BasePart or Terrain cell hit, the Vector3 point of intersection, the Vector3 surface normal at the point of intersection, and the Material of the BasePart or terrain cell hit.So you could do
local Part, Position, SurfaceNormal, Material = workspace:FindPartOnRay(ray, Character)
Hope this helps.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Are you talking about pcall(function()?
These are parameters.There can be multiple of them.
The success, error was used with a pcall function but hit, position = wasn't used in a pcall function