There is a problem in this script

Basically, when I use Moveto, the character moves to a certain point in the map, and not where it actually needs to go… This uses raycasting.

When I move a wall against any raycasting point, the player moves to a location. And if I move the wall right next to the player, it stays still. That’s where the player just moves at.

Code:

local __Move = true
local __Ray = game:GetService("RunService").Stepped:Connect(function()
	local P__ = RaycastParams.new()
	P__.FilterDescendantsInstances = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Parent:GetDescendants()
	P__.FilterType = Enum.RaycastFilterType.Blacklist
	local BackDynamicRaycast = workspace:Raycast(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position, game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector * -3, P__)
	local RightDynamicRaycast = workspace:Raycast(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position, game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.RightVector * 3, P__)
	local LeftDynamicRaycast = workspace:Raycast(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position, game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.RightVector * -3, P__)
	local FrontDynamicRaycast = workspace:Raycast(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position, game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector * 3, P__)
	if BackDynamicRaycast and __Move then
		print("Back")
		game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Parent.Humanoid:MoveTo(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector * 3.1)
	end
	if FrontDynamicRaycast and __Move then
		print("Front")
		game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Parent.Humanoid:MoveTo(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector * -3.1)
	end
	if LeftDynamicRaycast and __Move then
		print("Left")
		game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Parent.Humanoid:MoveTo(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.RightVector * 3.1)
	end
	if RightDynamicRaycast and __Move then
		print("Right")
		game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Parent.Humanoid:MoveTo(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.RightVector * -3.1)
	end
	-- Do not move if you're being blocked --
	if FrontDynamicRaycast and LeftDynamicRaycast and RightDynamicRaycast and BackDynamicRaycast then
		__Move = false
	else
		__Move = true
	end
end)

instead of doing character.Humanoid:Moveto(character.HumanoidRootPart.LookVector * 3.1) use the result of the raycast character.Humanoid:MoveTo(BackDynamicRaycast.Position)