You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to have a wallrunning script for a game i am making
What is the issue? Include screenshots / videos if possible!
After dying the player cant wallrun anymore. The script triggers for 1 frame then stops
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried debugging the code for hours, but to no avail.
The local script for it just calls a wallrun function on a module script, after dying i dont see any changes with the script’s memory and I have no clue why it just doesnt work.
We can’t help you if you don’t provide the code. The most likely reason it is breaking is that you aren’t updating the character, so when the player dies and a new character is added your script is still trying to reference the old character, which is nil.
There is absolutely no code to work with. But, you can set the character every time it respawns:
local currentcharacter --initialize the character here
--a bunch of code later
game.Players.LocalPlayer.CharacterAdded:Connect(function(character: Model)
currentcharacter = character --set the character to the respawned new instance
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
and here is the local script:
InputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Space then
Movement:Wallrun()
end
end)
theres some more, but those parts have nothing to do with what i think is most likely causing the error.