Hi guys, I recently tried to make my first wallrun system on Roblox by wathcing some tutorials and then tried to make my own, the problem is that it’s not working properly and I don’t even know why, I spent at least an hour debugging the code to detect errors but I couldn’t find how to fix it.
https://i.gyazo.com/e73457d2a1eec4313deaf7e9d62e9202.mp4
Here’s the code:
-Local-
local event = game.ReplicatedStorage.Wallrun
local char = script.Parent
local rootPart : Part = char.HumanoidRootPart
local MAX_RADIUS = 3
local _walls = {}
for _, part in workspace:GetDescendants() do
if part:GetAttribute("Wallrun") then
table.insert(_walls, part)
end
end
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = _walls
game:GetService("RunService").RenderStepped:Connect(function()
local raycast = workspace:Raycast(rootPart.Position, rootPart.CFrame.RightVector * MAX_RADIUS, params)
if raycast and raycast.Instance then
event:FireServer(true)
else
event:FireServer(false)
end
end)
-Server-
local event = game.ReplicatedStorage.Wallrun
local WallrunNormals = {}
local WallrunDirections = {}
local RAY_PARAMS = RaycastParams.new()
local MAX_RADIUS = 3
local WALLRUN_SPEED = 15
local WALLRUN_GRAVITY = 0
local _walls = {}
RAY_PARAMS.FilterType = Enum.RaycastFilterType.Include
for _, _wall in game:GetDescendants() do
if _wall:GetAttribute("Wallrun") then
table.insert(_walls, _wall)
end
end
RAY_PARAMS.FilterDescendantsInstances = _walls
local function InitPlayer(plr : Player)
plr:SetAttribute("Wallrunning", false)
local char = plr.Character or plr.CharacterAdded:Wait()
local rootPart = char.HumanoidRootPart
local LinearVelocity = Instance.new("LinearVelocity", rootPart)
LinearVelocity.MaxForce = math.huge
LinearVelocity.Enabled = false
LinearVelocity.Name = "WallrunVelocity"
local Attachment = Instance.new("Attachment", rootPart)
LinearVelocity.Attachment0 = Attachment
end
local function Wallrun(plr : Player, active : boolean)
local char = plr.Character or plr.CharacterAdded:Wait()
local rootPart : Part = char.HumanoidRootPart
local hum : Humanoid = char.Humanoid
local LinearVelocity : LinearVelocity = rootPart:WaitForChild("WallrunVelocity")
if active and plr:GetAttribute("Wallrunning") == false then
local RightRaycast = workspace:Raycast(rootPart.Position, rootPart.CFrame.RightVector * MAX_RADIUS, RAY_PARAMS)
if RightRaycast then
plr:SetAttribute("Wallrunning", true)
WallrunDirections[plr] = 1
WallrunNormals[plr] = Vector3.new(RightRaycast.Normal.Z, 0, -RightRaycast.Normal.X)
LinearVelocity.Enabled = true
local Velocity = WallrunNormals[plr] * WALLRUN_SPEED * -WallrunDirections[plr]
LinearVelocity.VectorVelocity = Vector3.new(Velocity.X, WALLRUN_GRAVITY, Velocity.Z)
end
elseif not active then
plr:SetAttribute("Wallrunning", false)
LinearVelocity.Enabled = false
WallrunNormals[plr] = Vector3.zero
WallrunDirections[plr] = 0
end
end
game.Players.PlayerAdded:Connect(InitPlayer)
event.OnServerEvent:Connect(Wallrun)
It barely works and I legit don’t know why,
Thanks in advance!