Noob scripting help (how does this work)

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer

tool.Equipped:Connect(function(mouse)

mouse.Button1Down:Connect(function()
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.hit.p - tool.Handle.CFrame.p).unit * 300)

local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

end)
end)

Sorry if there is any errors I typed on mobile. For the “local part, position = …” how does it set each variable? Are both part and position the same variable??

ALSO

I grabbed this script from wiki, how does “tool.Handle.CFrame.p” I mean what does “p” mean if it is not defined anywhere?

1 Like

CFrame.p = CFrame.Position

It’s basically a quicker and more efficient way of getting the position

4 Likes

Basically, CFrame.p (or CFrame.Position) is the Vector3 position component of a CFrame value. There is another Vector3 component of CFrame, which is the LookVector. More is explained on the Constructors section of the CFrame API page on the Developer Hub.

2 Likes

I was wondering more about what is part set to? What is position set to? Is it returning anything and if so what is it even returning??

1 Like

Part returns the 3D object that was obstructing the raycast. Position returns the exact Vector3 position of where the raycast ended. There’s another value, which is the Normal, being the angle of the surface the raycast hit.

2 Likes

It’s not “quicker and more efficient”, it’s slightly easier to type and deprecated. You shouldn’t be using it for new work.

5 Likes

Are deprecated terms buggy, or do people not like using them just because they are outdated?

2 Likes

Deprecated functions aren’t really buggy by any means, but deprecated functions usually have newer, quicker and more efficient replacements in their stead. There’s some deprecated functions because of performance issues, such as the second argument in Instance.new() which sets the parent (having to set the properties of an object after setting its parent will need it to be rendered to each client). There is also the slight chance a deprecated function could be removed at any given time, which is why it is good practice to use non-deprecated objects and functions.

2 Likes

I never thought of that. thanks for the tip, i will set the parent last when instantiating new objects in the future (unless otherwise necessary)

In the case of CFrame.p and CFrame.Position, these are both properties of a CFrame object. Using one over the other is not more efficient or quicker. p was deprecated in favour of Position for:

  • A more readable property in code (typically you should avoid single-letter variable names, some exceptions such as i as index in a for loop)

  • All lowercase methods and properties of Roblox instances were deprecated in favour PascalCase, given PascalCase is the standard naming convention for Roblox instances

As for Instance.new, the second argument is not deprecated, it is only bad practice if and only if you set other properties after parenting. If you are only creating an object and setting its parent and have no immediate need to change any other properties of it, the second argument is fine to use.

cc @DesiredFlamingFire @Dudeguy90539

2 Likes