Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = script.Parent
- local holdingKey = false
- local uis = game:GetService("UserInputService")
- local leftAnim = c.Humanoid:LoadAnimation(script:WaitForChild("WallrunLeft"))
- local rightAnim = c.Humanoid:LoadAnimation(script:WaitForChild("WallrunRight"))
- uis.InputBegan:Connect(function(inp, p)
- if not p and inp.KeyCode == Enum.KeyCode.F then
- holdingKey = true
- end
- end)
- uis.InputEnded:Connect(function(inp)
- if inp.KeyCode == Enum.KeyCode.F then
- holdingKey = false
- end
- end)
- game:GetService("RunService").Heartbeat:Connect(function()
- local raycastParams = RaycastParams.new()
- raycastParams.FilterType = Enum.RaycastFilterType.Blacklist; raycastParams.FilterDescendantsInstances = {c}; raycastParams.IgnoreWater = true
- local rayL = workspace:Raycast(c.HumanoidRootPart.CFrame.Position, -c.HumanoidRootPart.CFrame.RightVector * 3, raycastParams)
- local rayR = workspace:Raycast(c.HumanoidRootPart.CFrame.Position, c.HumanoidRootPart.CFrame.RightVector * 3, raycastParams)
- local ray = rayL or rayR
- if ray and holdingKey then
- if ray == rayL then
- if not leftAnim.IsPlaying then leftAnim:Play() end
- rightAnim:Stop()
- else
- if not rightAnim.IsPlaying then rightAnim:Play() end
- leftAnim:Stop()
- end
- local part = ray.Instance
- local weld = c.HumanoidRootPart:FindFirstChild("WallrunWeld") or Instance.new("WeldConstraint")
- weld.Name = "WallrunWeld"
- weld.Part0 = c.HumanoidRootPart
- weld.Part1 = part
- local bp = c.HumanoidRootPart:FindFirstChild("WallrunBodyPosition") or Instance.new("BodyPosition", c.HumanoidRootPart)
- bp.Name = "WallrunBodyPosition"
- bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- bp.Position = c.HumanoidRootPart.Position + c.HumanoidRootPart.CFrame.LookVector * 10
- else
- for i, child in pairs(c.HumanoidRootPart:GetChildren()) do
- if child.Name == "WallrunWeld" or child.Name == "WallrunBodyPosition" then
- child:Destroy()
- end
- end
- leftAnim:Stop()
- rightAnim:Stop()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement