I wanted to make a Wall Run and I have the Raycast set up and everything. The Script isn’t running at all and it went wrong somewhere. I added some prints to see where it went wrong and no prints came out and no errors either.
-- !strict
-- Services
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player: Player = Players.LocalPlayer
local Character = Player.CharacterAdded:Wait() or Player.Character
local Character = Player.CharacterAdded:Wait() or Player.Character
local HRP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
-- Modules
--[ Settings ]--
local Debug = true
local RayLength = 2
local FloorRayLength = 7
local TimeDelay = 0.2
local EndTime = 2
local LastSpacePressed = tick() -- If they press space twice, It'll begin to wall.
local raycastParmas = RaycastParams.new()
raycastParmas.FilterType = Enum.RaycastFilterType.Exclude
raycastParmas.FilterDescendantsInstances = {Character} -- Add your character to this if you don't want to detect walls for your character
local function DebugAttatchment(Position: Vector3) -- Using An Attachment to detect Where the wall is. (Debugging)
if not Debug then return end
local DebugAttachment = Instance.new("Attachment")
DebugAttachment.Visible = true
DebugAttachment.CFrame = CFrame.new(Position)
DebugAttachment.Parent = workspace.Terrain
task.delay(5, function()
DebugAttachment:Destroy()
end)
print("Wallrun began at "..tostring(Position))
end
local function LeftWallCheck() -- Checks if There is a wall to your Left.
print ("Left Wall")
return workspace:Raycast(HRP.Position, -HRP.CFrame.RightVector * RayLength, raycastParmas)
end
local function RightWallCheck() -- Checks if There is a wall to your Right.
print ("Right Wall")
return workspace:Raycast(HRP.Position, HRP.CFrame.RightVector * RayLength, raycastParmas)
end
local function FloorCheck() -- Checking If you are on the floor or not.
print ("Floor")
return workspace:Raycast(HRP.Position, -HRP.CFrame.UpVector * RayLength, raycastParmas)
end
--[ Main Functions ]--
function Wallrun()
print("WallRun Ran")
if not LeftWallCheck() and not RightWallCheck() then return end -- needs to go through these casts first.
local Speed = Character:WaitForChild("Humanoid").WalkSpeed -- only works because of movement module
if Speed > 14 then -- can't wallrun if no speed
if LeftWallCheck() then
DebugAttatchment(LeftWallCheck().Position)
HRP.Anchored = true
Humanoid.AutoRotate = false
task.wait(EndTime)
HRP.Anchored = false
Humanoid.AutoRotate = true
-- Physics & If they stop Wall Running they Jump off the walL.
UIS.InputBegan:Connect(function(input, GPE)
if input.KeyCode == Enum.KeyCode.Space then
-- They Jump off and End the Wall Run.
HRP.Velocity = HRP.CFrame.LookVector * Speed * 2
end
end)
else
DebugAttatchment(RightWallCheck().Position)
HRP.Anchored = true -- They cannot move and Face the wall they are against.
Humanoid.AutoRotate = false -- Face Direction they are moving so it doesn't look weird.
task.wait(EndTime)
HRP.Anchored = false
Humanoid.AutoRotate = true
-- Physics & If they stop Wall Running they Jump off the walL.
UIS.InputBegan:Connect(function(input, GPE)
if input.KeyCode == Enum.KeyCode.Space then
-- They Jump off and End the Wall Run.
end
end)
end
end
end
UIS.InputBegan:Connect(function()
Camera.ChildAdded:Connect(function(Child)
if Child.Name == "Viewmodel" then
raycastParmas.FilterDescendantsInstances = {Character,Child}
end
end)
end)
UIS.InputBegan:Connect(function(Input, GPE)
if GPE then return end
if Input.KeyCode == Enum.KeyCode.A or Enum.KeyCode.D then
print ("A and D Ran")
if tick() - LastSpacePressed <= TimeDelay then
Wallrun()
else
LastSpacePressed = tick()
end
end
end)