Wallrun script breaks after death

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix my script because every time a player dies for the first time it breaks
  2. What is the issue? Include screenshots / videos if possible!
    Wallrunning after death triggers the script for 1 frame
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried looking for solutions, tried resetting stuff after players die, and more but none of it works
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    module script:
local MovementModule = {}
MovementModule.__index = MovementModule
local Distance = 4
local MaxTime = 2
local Accuracy = .5
function MovementModule.CreateStats(Player)
	local NewMovement = setmetatable({}, MovementModule)
	NewMovement.Player = Player
	NewMovement.Wallrunning = false
	NewMovement.WallrunDebounce = false
	NewMovement.DashDebounce = false
	NewMovement.Player.CharacterAdded:Connect(function()
		print("module detected respawn")
		NewMovement.Wallrunning = false
		NewMovement.WallrunDebounce = false
		NewMovement.DashDebounce = false
		NewMovement.Player = Player
	end)
	return NewMovement
end

function MovementModule:Wallrun()
	local Player = self.Player
	local hrp = Player.Character.HumanoidRootPart
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = {Player.Character:GetDescendants()}
	local Wallrun = coroutine.create(function()
		local StartTime = tick()
		self.Player.PlayerGui.CooldownUI.Frame.Wallrun.Slider.BackgroundColor = BrickColor.new(255, 0, 0)
		while self.Wallrunning do
			wait(.01)
			local rayL = workspace:Raycast(hrp.Position, hrp.CFrame.RightVector * -Distance, raycastParams)
			local rayR = workspace:Raycast(hrp.Position, hrp.CFrame.RightVector * Distance, raycastParams)
			if Player.Character.Humanoid:GetState() ~= Enum.HumanoidStateType.Landed then
				if rayL or rayR then
					if tick() - StartTime <= MaxTime then
						if rayL then
							local Normal = rayL.Normal
							local Direction = Normal:Cross(Vector3.new(0,1,0))
							Direction = -Direction
							local Character = Player.Character
							local Vector = (Direction * Character.Humanoid.WalkSpeed * 2 + Vector3.new(0, Character.HumanoidRootPart.Velocity - Character.HumanoidRootPart.Velocity)).Unit
							hrp.Velocity = math.clamp((Character.HumanoidRootPart.Velocity * (1)).Magnitude, 40, 50 ) * Vector + Vector3.new(0, Character.HumanoidRootPart.Velocity.Y + workspace.Gravity / 33, 0)
						elseif rayR then
							local Normal = rayR.Normal
							local Direction = Normal:Cross(Vector3.new(0,1,0))
							local Character = Player.Character
							local Vector = (Direction * Character.Humanoid.WalkSpeed * 2 + Vector3.new(0, Character.HumanoidRootPart.Velocity - Character.HumanoidRootPart.Velocity)).Unit
							hrp.Velocity = math.clamp((Character.HumanoidRootPart.Velocity * (1)).Magnitude, 40, 50 ) * Vector + Vector3.new(0, Character.HumanoidRootPart.Velocity.Y + workspace.Gravity / 33, 0)
						end
					else
						self.Wallrunning = false
						coroutine.yield()
						
					end
				else
					self.Wallrunning = false
					coroutine.yield()
					
				end
			else
				self.Wallrunning = false
				coroutine.yield()
				
			end
		end
	end)
	if self.Wallrunning == true then
		self.Wallrunning = false
		self.WallrunDebounce = true
		hrp.Velocity = Vector3.new(hrp.Velocity.X, 50, hrp.Velocity.Z)
	end
	local rayL = workspace:Raycast(hrp.Position, hrp.CFrame.RightVector * -Distance, raycastParams)
	local rayR = workspace:Raycast(hrp.Position, hrp.CFrame.RightVector * Distance, raycastParams)
	if Player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
		if rayL or rayR then
			if not self.WallrunDebounce then
				self.Wallrunning = true
				hrp.Velocity = Vector3.new(hrp.Velocity.X, hrp.Velocity.Y / 3, hrp.Velocity.Z)
				coroutine.resume(Wallrun)
			end
		end
	end
end

function MovementModule:Dash()
	if not self.DashDebounce then
		local Player = self.Player
		Player.PlayerGui.CooldownUI.Frame.Wallrun.Slider.BackgroundColor = BrickColor.Blue()
		local hrp = Player.Character.HumanoidRootPart
		self.DashDebounce = true
		self.WallrunDebounce = false
		hrp.Velocity = (hrp.CFrame.LookVector * 150) + Vector3.new(0, 45, 0)
		local StartScale = Player.PlayerGui.CooldownUI.Frame.Dash.Slider.Size
		Player.PlayerGui.CooldownUI.Frame.Dash.Slider.Size = UDim2.new(0, 0, 0, 50)
		repeat
			Player.PlayerGui.CooldownUI.Frame.Dash.Slider.Size += UDim2.new(0, 2.5, 0, 0)
			wait(((200 / 2.5) / (200 / 2.5 / 2.5)) / (200 / 2.5))
		until Player.PlayerGui.CooldownUI.Frame.Dash.Slider.Size == StartScale
		self.DashDebounce = false
	end
end

return MovementModule

local script:

script.Parent:WaitForChild("PlayerModule"):WaitForChild("CameraModule"):WaitForChild("MouseLockController"):WaitForChild("BoundKeys").Value = "LeftControl"
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local InputService = game:GetService("UserInputService")
local MovementModule = require(game:GetService("ReplicatedStorage").Movement)
local Movement = MovementModule.CreateStats(Player)
InputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.Space then
		Movement:Wallrun()
	end
	if Input.KeyCode == Enum.KeyCode.LeftShift then
		Movement:Dash()
	end
end)

game:GetService("RunService").RenderStepped:Connect(function()
	if Character.Humanoid:GetState() ~= (Enum.HumanoidStateType.Freefall) then
		Player.PlayerGui.CooldownUI.Frame.Wallrun.Slider.BackgroundColor = BrickColor.Blue()
		Movement.WallrunDebounce = false
		Movement.Wallrunning = false
	end
end)

Player.CharacterAdded:Connect(function()
	Movement.Wallrunning = false
	Movement.WallrunDebounce = false
	Movement.DashDebounce = false
end)
3 Likes

try to put script in “StarterCharacterScripts” or “StarterPlayerScripts”

1 Like

the local script is already in starter player scripts. The module script runs the same as a local script would, its just more performant

1 Like

ok ive debugged that right after the “while self.wallrunning do” part that wallrunning is false but it still runs, ill try to figure out more details but thats where the issue originates from i believe

1 Like
Player.Character:FindFirstChild("Humanoid").Died:Connect(function()
    repeat wait()
        Movement.Wallrunning = false
	    Movement.WallrunDebounce = false
	    Movement.DashDebounce = false
    until Movement.Wallrunning == false and Movement.WallrunDebounce == false and Movement.DashDebounce == false
end)
1 Like

same issue, i think what i said above this post tho was wrong. I think my time part (using tick()) is getting bugged from it.

1 Like

Makes sense. Is it working now?

1 Like

it wasnt getting bugged, just roblox debugging tools suck. Im still having the same issue. Whenever i put a breakpoint on line 79 (module script) then self.Wallrunning is equal to true in the watch menu, but otherwise its equal to false. Im confused why this happens because it ruins the debugging process.

1 Like

i think that the script gets slower or something after dying because before dying this doesnt happen at all, but after dying this exact statement applies to every time the function runs

1 Like

the loop runs fine when i use breakpoints to see what happens, but if i put a wait or anythign else to slow it down it just doesnt work. I think its a roblox bug because this wouldnt happen otherwise, super strange

1 Like

the error was at line 20 in the local script, no clue why but that line of code broke everything. IM SO HAPPY I FOUND THE ERROR IVE BEEN DEBUGGING FOR 4 DAYS. i want a tool that allows you to see which line of code changes something in the watch section, it would have helped me solve this in 2 minutes instead of 4 days.

1 Like

It should be in starterCharacter scripts, not starter player scripts. Try that.

1 Like

I have it in starter player to keep scripts organized and so i dont have too many scripts for my friends to go around and spontaneously break somehow. I know its bad practice but it works for me lol

1 Like

I am not sure if you understand this. It is breaking because it is not parented correctly, if I understand your problem. If it is in starterplayerscripts that means that it will be parented to the player. It will not reload when you reset. So animations will not play.