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

I saw a script from devforum and I don't understand it?

link for script

local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)

if withinScreenBounds then
   -- We have successfully detected if the player can see the part.
end

okay so you make two variables : _ and withinScreenBounds. But why do you need _ if you only use withinScreenBounds?

3 answers

✓ Accepted answer

The method used in the code :WorldToScreenPoint() returns a tuple in this case, essentially in the devforum code the developer wanted to store the tuple's return information in 2 variables having the first one as "underscore" ( _ ) because he/she doesn't want to really use it and marks it as irrelevant by naming it that way.

But essentially the method first returns a Vector3 for X and Y positions in the screen and a Z factor for depth and the second value returned from the method is just a bool that indicates if the point is within the screen, more information here:

https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint

Normally some scripters do this incase you need to add another variable later depending on what you are trying to script, of course they can easily remove it afterwards if it is not needed. The script would work just as well as if it didn't have the second variable.

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