Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you use ray for a placing system?

Asked by 7 years ago

How do you use ray to detect if a model is hanging over the players base when making a placing system?

1 answer

Log in to vote
0
Answered by 7 years ago

If your model has a Primary Part, you can take that and cast a ray from it, and then check if the part it hits is parented to the players base.

--Sample Code

local playerBase
local modelChecked
local maxDistance = 128 --Or some other number, I don't know.
--Assign all of this

local ray = Ray.new(modelChecked.PrimaryPart.CFrame.p, Vector3.new(0, -1, 0) * maxDistance)

local part, pos = workspace:FindPartOnRay(ray, modelChecked)

if (part.Parent == playerBase) then
    --Do whatever you want to do in here
end


Ad

Answer this question