Hello scripters. I am currently facing an issue that I cant resolve to my knowledge at the moment.
What I am trying to Achieve
What I am trying to achieve is that I want to spawn a model a certain radius away from me while checking if there is nothing under it. If there is nothing under it, I shoot a ray down and if it will either drag the model down to that position or destroy it if there is nothing under it.
The issue that I am facing
The issue I’m facing currently is the ray. I am struggling to set the position down to the hit position. Here is the snippet of code that I have.
local rayOrigin = playerComputer:GetBoundingBox().Position
local rayDirection = Vector3.new(0, -100, 0)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if raycastResult then
local hitPosition = raycastResult.Position
local raycastCFrame = CFrame.new(hitPosition) + Vector3.new(0, 1, 0) -- Adjust the vector offset here manually
playerComputer:MoveTo(raycastCFrame)
else
playerComputer:Destroy()
end
The error I am having from the console are on these line
local raycastCFrame = CFrame.new(hitPosition) + Vector3.new(0, 1, 0) -- Adjust the vector offset here manually
playerComputer:MoveTo(raycastCFrame)
I tried looking on this forum here Finding Hit position with new raycasting? Help! But I couldn’t find what I needed.
Does anyone have a clue what I am doing wrong?