I have watched a video about implementing a vault system into my game, by LTMaiko. I took his script, and edited it so that the player would vault over the part when they press space. The code I used is here:
local plr = game:GetService(“Players”).LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local HRP = char:WaitForChild(“HumanoidRootPart”)
local Hum = char:WaitForChild(“Humanoid”)
local CA = Hum:LoadAnimation(script:WaitForChild(“ClimbAnim”))
local vaultSound = script.Vault
local UIS = game:GetService(“UserInputService”)
local ledgeavail = true
UIS.InputBegan:Connect(function(key)
local r = Ray.new(HRP.Position, HRP.CFrame.LookVector * 7 + HRP.CFrame.UpVector * -5)
local part = workspace:FindPartOnRay(r,char)
if part and ledgeavail and key.KeyCode == Enum.KeyCode.Space then
if part:FindFirstChild(“CanVault”) then
if Hum.FloorMaterial ~= Enum.Material.Air then
ledgeavail = false
local Vel = Instance.new(“BodyVelocity”)
Vel.Parent = HRP
Vel.Velocity = Vector3.new(0,0,0)
Vel.MaxForce = Vector3.new(1,1,1) * math.huge
Vel.Velocity = HRP.CFrame.LookVector * 10 + Vector3.new(0,15,0) + HRP.Velocity / 1.3
CA:Play(0.1, 1, 1)
game.Debris:AddItem(Vel, .15)
vaultSound:Play()
wait(0.75)
ledgeavail = true
end
end
end
end)
There are no bugs or errors with this script. The only problem is that I have to manually insert a value called “CanVault” inside of the part so that the script knows that it can vault over it. I want my script to detect a ledge so that my player can vault over it.