Hello! I want to make a wallrun system similar to the examples below:
I’ve already got a script for something similar, however it doesn’t include the system I want:
local function LoseGrip()
Humanoid.AutoRotate = true
WallGripLeft = 0
GrabWait = GrabCooldown
Humanoid.WalkSpeed = OldWalkspeed
CurrentConstraint:Destroy()
CurrentConstraint = nil
CurrentAttachment:Destroy()
CurrentAttachment = nil
WallJumpAnimTrack:Stop()
Humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
end
RunService.Heartbeat:Connect(function(deltaTime)
if CurrentConstraint == nil and GrabWait <= 0 and Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
-- When the character is falling in front of a wall, attach it to the wall.
local ray = Ray.new(RootPart.Position, RootPart.CFrame.LookVector * 1.7)
local hit, point, normal = workspace:FindPartOnRay(ray, script.Parent)
local hitTag = hit and hit:FindFirstChild("_Wall")
if hitTag then
Humanoid.AutoRotate = false
WallAttachSound:Play()
-- Temporarily attach the Humanoid to the wall.
local normalCFrame = hit.CFrame:ToObjectSpace(CFrame.new(Vector3.new(0, 0, 0), normal))
normalCFrame = normalCFrame - normalCFrame.Position
local offsetCFrame = CFrame.new((hit.CFrame:inverse() * RootPart.CFrame).Position)
local newCFrame = hit.CFrame * offsetCFrame * normalCFrame
RootPart.CFrame = newCFrame
GripLookVector = newCFrame.LookVector
OldWalkspeed = Humanoid.WalkSpeed
Humanoid.WalkSpeed = 0
CurrentWall = hit
CurrentAttachment = Instance.new("Attachment")
CurrentAttachment.Name = "WallJumpAttachment"
CurrentAttachment.CFrame = offsetCFrame * normalCFrame
CurrentAttachment.Parent = hit
CurrentConstraint = Instance.new("BallSocketConstraint")
CurrentConstraint.Attachment0 = CurrentAttachment
CurrentConstraint.Attachment1 = RootAttachment
CurrentConstraint.Name = "WallWeld"
CurrentConstraint.Parent = RootPart
WallJumpAnimTrack:Play()
WallGripLeft = WallGripDuration
if CurrentWall:FindFirstChild('_Wall') then
if CurrentWall._Wall:FindFirstChild('WallRun') then
-- the velocity should be the value of this WallRun value
WallGripLeft = math.huge
end
if CurrentWall._Wall:FindFirstChild('StickTime') then
WallGripLeft = CurrentWall._Wall.StickTime.Value
end
end
game.Debris:AddItem(CurrentAttachment, WallGripLeft + 1)
game.Debris:AddItem(CurrentConstraint, WallGripLeft + 1)
JumpWait = JumpCooldown
end
elseif CurrentConstraint ~= nil then
-- When the character holds on to the wall for too long, make it lose hold.
WallGripLeft = math.max(0, WallGripLeft - deltaTime)
if WallGripLeft <= 0 then
LoseGrip()
end
end
JumpWait = math.max(0, JumpWait - deltaTime)
GrabWait = math.max(0, GrabWait - deltaTime)
end)
Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
-- When the character jumps and they're attached to a wall, propel them away from it.
if CurrentConstraint ~= nil and Humanoid.Jump and JumpWait <= 0 then
local releasePower = 1
if CurrentWall:FindFirstChild('_Wall') then
if CurrentWall._Wall:FindFirstChild('ReleasePower') then
releasePower = CurrentWall._Wall.ReleasePower.Value
end
end
LoseGrip()
-- Propel the character away from the wall.
WallJumpSound:Play()
RootPart.Velocity =
RootPart.Velocity +
Vector3.new(0, Humanoid.JumpPower, 0) +
(GripLookVector * Humanoid.JumpPower * releasePower)
end
end)
Can someone help me modify this script so that if the hit._Wall contains a NumberValue called “WallRun”, it makes the player travel along the wall in the direction of the top face.