Learn
Engine Class
RayValue

Summary
Properties
Events
changed(value: Ray):RBXScriptSignal
Deprecated
Inherited Members
Code Samples
Rays, RayValue and Raycasting
local partA = workspace.PartA
local partB = workspace.PartB
local origin = partA.Position
local direction = partB.Position - partA.Position
local ray = Ray.new(origin, direction)
local rayValue = Instance.new("RayValue")
rayValue.Value = ray
rayValue.Name = "PartA-to-PartB Ray"
rayValue.Parent = workspace
-- Raycast to find any parts in between PartA and PartB
local part = workspace:FindPartOnRay(ray)
if part then
print("Hit part: " .. part:GetFullName())
else
-- This ought to never happen, as our ray starts at PartA
-- and points towards PartB, so we should always hit PartB
-- or some other part.
print("No part hit!")
end

API Reference
Properties
Value
Read Parallel
Simulation Access
RayValue.Value:Ray

Events
Changed
RayValue.Changed(value:Ray):RBXScriptSignal
Parameters
value:Ray
Code Samples
How to Use RayValue.Changed
local value = Instance.new("RayValue")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
local start = Vector3.new(0, 0, 0)
local lookAt = Vector3.new(10, 10, 10)
local ray = Ray.new(start, (lookAt - start).Unit)
value.Value = ray

changed
Deprecated

©2026 Roblox Corporation. Roblox, the Roblox logo and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.