local function raycast(origin, direction)
local raycastResult = workspace:Raycast(origin, direction) -- Don't worry about the origin and direction error
if raycastResult and raycastResult.Instance then
return raycastResult.Position
end
return nil
end
You’re not returning a position vector when you don’t hit anything - which happens when you’re shooting into the sky. The position vector when the raycast doesn’t hit a part is equal to origin + direction.
I think the ray hits the object you want to place, so you can drag it up by holding your mouse on the object. Try filtering it out using:
local function raycast(origin, direction, blacklist)
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = blacklist
local raycastResult = workspace:Raycast(origin, direction, raycastparams)
if raycastResult and raycastResult.Instance then
return raycastResult.Position
end
return nil
end