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

How do I make a part the size of a ray?

Asked by
Cikeruw 14
2 years ago

i have been trying to make my part the size of the ray but i do not know what to put. I would appreciate if someone would help me out.

Here is my code

local RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(Player,mouseCframe)
    local Mouse = Player:GetMouse()
    local Origin = script.Parent.Position
    local Direction = (mouseCframe - Origin).Unit
    Direction = Direction * 100
    local ray = Ray.new(Origin,Direction)
    local Parts = workspace:FindPartOnRay(ray,nil)
    print(Parts)
    local Part = Instance.new("Part",game.Workspace)
    Part.Anchored = true
    local length = (Direction - Origin).Magnitude
    Part.Size = Vector3.new(0.5,0.5,length)
    Part.Position = ???
end)

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

Instead of part.position do

Part.CFrame = CFrame.lookAt(origin, ray.Position)*CFrame.new(0, 0, -length/2)
end
Ad

Answer this question