Weird behavior with raycast script?

Hi! Quick little request here, I am attempting to make a script that’ll raycast to the floor and basically place a part at that points position-- and whilst it is doing that, the part is ending up halfway into the floor.

amazing|357x163

I have never used raycasts up until this point, so this is all still very new to me. How would I make it so that the bottom of the part touches the top here and doesn’t get half stuck? I have the code right here.

local startPos = script.Parent.Position
local direction = Vector3.new(0, -1, 0).unit
local magnitude = 500

local ray = Ray.new(startPos, direction * magnitude)
local foundPart, endPos = workspace:FindPartOnRay(ray, script.Parent, false, true)

if foundPart == nil then
print(“Part isn’t above a floor!”)
else
script.Parent.Position = endPos
end

That’s actually deprecated if you didn’t know, try using the workspace:Raycast() function instead

local startPos = script.Parent.Position
local direction = Vector3.new(0, 0, 0).Unit --Not sure why you're wanting to Raycast -1 down the Y axis
local Magnitude = 500

local Result = workspace:Raycast(startPos, direction * Magnitude)

if not Result then
    print("Part isn't above a floor!")
else
    script.Parent.Position = Result.Position
end