How would you make a wall running script?

Heya!
I was wondering for the past few days now of how to make a wall run script. All of my scripts don’t work :frowning:. So, I tried searching something on Google. Still, nothing.

Here is my current code, but doesn’t work :frowning: :

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
	while char and wait() do
		local hrp = char:WaitForChild("HumanoidRootPart")
		local rightRay = workspace:Raycast(hrp.Position, hrp.CFrame.lookVector * 300)
		local leftRay = workspace:Raycast(hrp.Position, -hrp.CFrame.lookVector * 300)
		if not rightRay or not leftRay then return end
		if rightRay.Instance then
			print(rightRay.Instance.Name.." | "..tostring(rightRay.Instance.Position))
		end
		if leftRay.Instance then
			print(leftRay.Instance.Name.." | "..tostring(leftRay.Instance.Position))
		end
		if rightRay.Instance and leftRay.Instance then
			if hrp:FindFirstChildOfClass("BodyVelocity") then
				hrp:FindFirstChildOfClass("BodyVelocity"):Destroy()
			end
			local rr_mag = (rightRay.Instance.Position - hrp.Position).magnitude
			local lr_mag = (leftRay.Instance.Position - hrp.Position).magnitude
			local min = math.min(rr_mag, lr_mag)
			print(rightRay.Instance.Name, rightRay.Normal)
			local chosenRay = nil
			if min == rr_mag then chosenRay = rightRay else chosenRay = leftRay end
			if chosenRay.Normal.Y ~= 0 then return end
			local bv = Instance.new("BodyVelocity", hrp)
			bv.MaxForce = Vector3.new('inf','inf','inf')
			bv.Velocity = chosenRay.Normal:Cross(Vector3.new(0, 1, 0))
		end
		
	end
end)

end)

Thanks,
Dragon

p.s I don’t want something similar to EgoMoose’s gravity controller module

1 Like

What don’t you like about EgoMoose’s gravity controller module?

This is a scripting support forum so it may help to show what you’ve tried and how you’ve scripted it.

I recommend watching this tutorial this may help you

2 Likes

I just didn’t want something holding you up when you should clearly fall off. I wanted something like the wall running in Karlson 3D

This is good, but not what I want. I want the player to be able to switch walls as well.