Need help with wallrun script

Issue:

I can only wallrun left after wallrunning right and vice versa.

What I Want;

I only want to be able to wallrun twice in a row on the same side, I don’t want to be able to wallrun wallrun left after wallrunning right and vice versa. If you understand how Parkour Reborn’s wallrun system works I’m trying to get it similar to that.

Script:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")

task.wait(0.5)

local module = require(script.ModuleScript)
local inputServ = game:GetService("UserInputService")
local head = plr.Character:FindFirstChild("Head")
local torso = plr.Character:FindFirstChild("Torso")
local root = plr.Character:FindFirstChild("HumanoidRootPart")
local runServ = game:GetService("RunService")

local defaultGravity = workspace.Gravity
local sett = script.Settings 
local wallrunSound = game.ReplicatedStorage.Sounds.WallRunSound
local releseSound = game.ReplicatedStorage.Sounds.JumpSound

local movementMark = workspace.MovementUI.SurfaceGui.WallrunMarker1
local movementMark2 = workspace.MovementUI.SurfaceGui.WallrunMarker2

local wallrunKeybind = Enum.KeyCode.Space

local landed = true
local holdingSpace = false
local wallranL = false
local wallranR = false
local wallranB = false

local leftAnim = Instance.new("Animation")
leftAnim.AnimationId = "rbxassetid://16444022039"
local leftAnimTrack = hum:LoadAnimation(leftAnim)

local rightAnim = Instance.new("Animation")
rightAnim.AnimationId = "rbxassetid://16444027910"
local rightAnimTrack = hum:LoadAnimation(rightAnim)

hum.StateChanged:Connect(function(old,new)
	if new == Enum.HumanoidStateType.Freefall or new == Enum.HumanoidStateType.Jumping then
		landed = false

	elseif new == Enum.HumanoidStateType.Landed or new == Enum.HumanoidStateType.Dead then
		landed = true
		wallranL = false
		wallranR = false
		wallranB = false
		movementMark.ImageTransparency = 0.85
		movementMark2.ImageTransparency = 0.85
	end
end)

inputServ.InputBegan:Connect(function(input)
	if input.KeyCode == wallrunKeybind then
		holdingSpace = true
	end
end)

inputServ.InputEnded:Connect(function(input)
	if input.KeyCode == wallrunKeybind then
		holdingSpace = false
	end
end)

local last = tick()

runServ.RenderStepped:Connect(function()

	local t = tick()
	local dt = t - last

	last = t

	local RPart,RPosition = module.Ray(root.Position,root.CFrame.XVector * 5,plr.Character)
	local LPart,LPosition = module.Ray(root.Position,root.CFrame.XVector * -5,plr.Character)

	if LPart and not RPart and not landed and holdingSpace and torso.Velocity.Y > -65 and torso.Velocity.Y < -1 then
		torso.Velocity = torso.Velocity + Vector3.new(0,-0,0) *dt
		workspace.Gravity = workspace.Gravity + (workspace.Gravity-5) *dt
		if not wallranL then
			leftAnimTrack:Play()
			workspace.Gravity = 10
			wallrunSound:Play()
			wallranL = true
			plr:SetAttribute("WallRunning", true)
			movementMark.ImageTransparency = 0
			--print(plr.Character:GetAttribute("WallRunning"))
		end

	elseif not LPart and RPart and not landed and holdingSpace and torso.Velocity.Y > -65 and torso.Velocity.Y < -1 then
		torso.Velocity = torso.Velocity + Vector3.new(0,0,0) *dt
		workspace.Gravity = workspace.Gravity + (workspace.Gravity-5) *dt
		if not wallranR then
			rightAnimTrack:Play()
			workspace.Gravity = 10
			wallrunSound:Play()
			wallranR = true
			plr:SetAttribute("WallRunning", true)
			movementMark2.ImageTransparency = 0
			--print(plr.Character:GetAttribute("WallRunning"))
		end

	elseif RPart and LPart and not landed and holdingSpace and torso.Velocity.Y > -65 and torso.Velocity.Y < -1 then
		torso.Velocity = torso.Velocity + Vector3.new(0,0,0) *dt
		workspace.Gravity = workspace.Gravity + (workspace.Gravity-5) *dt
		if not wallranB then
			workspace.Gravity = 10
			wallrunSound:Play()
			wallranB = true
			plr:SetAttribute("WallRunning", true)
			--print(plr.Character:GetAttribute("WallRunning"))
		end

	elseif landed or not holdingSpace or (not RPart and not LPart) or (torso.Velocity.Y < -65 and torso.Velocity.Y < -1) then
		if leftAnimTrack.IsPlaying or rightAnimTrack.IsPlaying then
			torso.Velocity = Vector3.new(torso.Velocity.X,sett.WallRunningEndingVelocity.Value,torso.Velocity.Z)
		end

		workspace.Gravity = defaultGravity
		leftAnimTrack:Stop()
		rightAnimTrack:Stop()
		wallrunSound:Stop()
		plr:SetAttribute("WallRunning", false)

	end
end)
1 Like