Help wanted, Problem with the construction of a Coordinated Frame

Greetings, Gentlemen,

I Am trying to make the player stick to the wall, Fortunately, It is working, From only one side of the wall, The side of the Look Vector, How can I make it work from all sides?

wait()
local Player = game.Players:GetPlayerFromCharacter(script.Parent)
local Character = Player.Character or Player.CharacterAdded:Wait()
local RunService = game:GetService("RunService")

local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = {Character}
RaycastParameters.FilterType = Enum.RaycastFilterType.Exclude

local debounce = false -- Add a debounce variable

local function StickToWall()
	if debounce then return end -- Check if debounce is true, if so, return

	local RaycastResult = workspace:Raycast(Character.PrimaryPart.Position, Character.PrimaryPart.CFrame.LookVector.Unit * 2, RaycastParameters)

	if RaycastResult then
		if RaycastResult.Instance:HasTag("ClimbablePart") and Character.Climbing.Value ~= true then
			print("Sticking to the wall at:", RaycastResult.Position)
			local WorldUp = Character:GetPrimaryPartCFrame().UpVector
			local Normal = RaycastResult.Normal
			local LookVector = Normal * -1 
			local RightVector = Normal:Cross(WorldUp)
			local NeededCFrame = CFrame.fromMatrix(RaycastResult.Position - Vector3.new(0, 0, -1), RightVector, WorldUp, -LookVector)
			
			
			game.ReplicatedStorage["Climbing Resever."]:FireServer(NeededCFrame, RaycastResult.Instance)
		end
	end
end

local function OnStepped()
	StickToWall()
end

-- Connect the function to the Stepped event
RunService.RenderStepped:Connect(OnStepped)
1 Like