Rays are a very interesting part of Roblox because they can be used for many different purposes. They can be used for anti-exploit purposes for checking whether a player is fly hacking or to create ranged weapons. Also many more things…
The way that you create a ray is by using the inbuilt function:
Ray.new(Vector3 origin, Vector3 direction)
This would create an invisible ‘beam’ that can be used to hit parts and return true.
If you wanted to find a part that the ray hits, you would use another inbuilt function:
local part = workspace:FindPartOnRay(ray,[optional] parts to ignore)
What this does is it finds the part that the ray has hit. If it doesn’t hit anything, part will be nil.
You can also use this method to get the Vector3 value in the place that the ray hits an object; This can be done by adding the variable position into the above function:
local part,position = workspace:FindPartOnRay(ray,[optional] parts to ignore)
There is also a more advanced ‘surface normal’ variable that can be added and is probably way to complicated for what you want from raycasting. Having said that, this link is a good place to get started.
As for your idea of invisible parts, you could do something like this:
game.Players.PlayerAdded:Connect(function(player)
local invisiblePart = workspace.InvisiblePart
local Ignore = player.Character
while wait(2) do --You can change the wait value to anything
local Ray = Ray.new(player.Character.HumanoidRootPart.CFrame.p,Vector3.new(0,-5,0)) --Creating the ray down from the character
local part = workspace:FindPartOnRay(Ray,Ignore) -- Finding the part that the ray hits
if part then -- If there is a part
if part == invisiblePart then -- If the part is the one you want to be invisible
invisiblePart.Transpareny = 1
else
invisiblePart.Transparency = 0
end
end
end)
These links may also be useful:
Raycasting article
How to make a raycasting laser gun
Hope this helps!