Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleporting Player to Raycast Hit Position places Character on top of object?

Asked by 1 year ago

Title says it all, here's the code I currently have as well as a video for visual representation of what it looks like, please help!

Video

local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = {Character}
local ray = workspace:Raycast(Character['HumanoidRootPart'].Position, Character['HumanoidRootPart'].CFrame.LookVector * 25,rayParams)
VisibleRay(Ray.new(Character['HumanoidRootPart'].Position, Character['HumanoidRootPart'].CFrame.LookVector * 25))
if ray then
    local Hit,Position = ray.Instance,ray.Position
    if Hit.Parent:FindFirstChildOfClass('Humanoid') then
        Character['HumanoidRootPart'].CFrame = Hit.CFrame -     Character['HumanoidRootPart'].CFrame.lookVector * 5
    else
        Character:MoveTo(Vector3.new(Position.X,Character['HumanoidRootPart'].Position.Y,Position.Z))
    end
else
    Character['HumanoidRootPart'].CFrame = Character['HumanoidRootPart'].CFrame + Character['HumanoidRootPart'].CFrame.lookVector * 25
end

Answer this question