I’m trying to make a laser using raycast, and I don’t know what I’m doing wrong.
function laser()
if tool:FindFirstChild("Laser") then
local laserorigin = tool.Laser.Main.StartAttachment
local laserparams = RaycastParams.new()
laserparams.FilterDescendantsInstances = {tool.Laser.Main}
laserparams.FilterType = Enum.RaycastFilterType.Blacklist
local rayresult = workspace:Raycast(laserorigin, tool.Laser.Main.StartAttachment.Orientation, laserparams)
local hit = rayresult.Instance
tool.Laser.Main.EndAttachment.Position = Vector3.new(0, (hit.Position.Y-tool.Laser.Main.Position.Y)+rayresult.Position.Y, 0)
end
end
function laser()
if tool:FindFirstChild("Laser") then
local laserorigin = tool.Laser.Main.StartAttachment
local laserparams = RaycastParams.new()
laserparams.FilterDescendantsInstances = {tool.Laser.Main}
laserparams.FilterType = Enum.RaycastFilterType.Blacklist
local rayresult = workspace:Raycast(laserorigin.Position, tool.Laser.Main.StartAttachment.Orientation, laserparams)
local hit = rayresult.Instance
tool.Laser.Main.EndAttachment.Position = Vector3.new(0, (hit.Position.Y-tool.Laser.Main.Position.Y)+rayresult.Position.Y, 0)
end
end
You’re feeding an instance into a function that expects a Vector3. Also, you’re assuming that the raycast hits something.
function laser()
if tool:FindFirstChild("Laser") then
local laserorigin = tool.Laser.Main.StartAttachment
local laserparams = RaycastParams.new()
laserparams.FilterDescendantsInstances = {tool.Laser.Main}
laserparams.FilterType = Enum.RaycastFilterType.Blacklist
local rayresult = workspace:Raycast(laserorigin.WorldPosition, tool.Laser.Main.StartAttachment.Orientation, laserparams)
local hit = rayresult.Instance
tool.Laser.Main.EndAttachment.Position = Vector3.new(0, (hit.Position.Y-tool.Laser.Main.Position.Y)+rayresult.Position.Y, 0)
end
end