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

what does it mean when one variable has multiple variable read description?

For example this variable has 3 variables hit,position,normal does that mean that 3 of these variables are the same?

local hit, position, normal = Workspace:FindPartOnRay(ray, ignore)

1 answer

✓ Accepted answer

In Lua you can return multiple values in a function (this is quite rare in programming languages) and other languages get around this by returning an array/list of values.

In the case of FindPartOnRay if a part intersect the ray then additional information is included that developers may or may not use.

I think you might be confusing a function which can return different types with a function that can return multiple values.

Example

-- multiple return <string, string>
local function a() return "A", "B" end

print(a())

-- different return types <string, boolean>
local function b(val) 
	if val then
		return "A"
		
	else
		return false
	end
end

print(b(true))
print(b(false))

Hope this helps.

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