Vault and animation bug

i want to achieve a working vault script

my vault script does not boost me forward, and it stops my animations

any ideas? here is the script i am using also.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local vaultCooldown = false – Prevents spamming

– Customizable settings
local speedBoost = 0 – Extra speed after the vault
local vaultDuration = 0.1-- Duration of the vault movement
local animationId = “rbxassetid://128897073877701” – Replace with a speed vault animation

– Physics settings
local vaultForce = Vector3.new(0, 10, 20) – Customizable force applied during the vault

– Utility to check for vaultable objects
function isVaultable(hit)
– Define criteria for vaultable objects, e.g., height or tag
local maxHeight = 5 – Maximum height in studs for vaultable objects
local minHeight = 1 – Minimum height in studs for vaultable objects
local height = hit.Size.Y

if height <= maxHeight and height >= minHeight then
	return true
end
return false

end

– Vault function
function performVault(obstacle)
if vaultCooldown then return end
vaultCooldown = true

-- Play animation
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
	local vaultAnim = Instance.new("Animation")
	vaultAnim.AnimationId = animationId
	local playAnim = animator:LoadAnimation(vaultAnim)
	playAnim:Play()
end

-- Physics boost
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(1e6, 1e6, 1e6)
bodyVelocity.Velocity = humanoid.RootPart.CFrame.LookVector * vaultForce.Z + Vector3.new(0, vaultForce.Y, 0)
bodyVelocity.Parent = character.PrimaryPart

-- Cleanup after vault duration
game.Debris:AddItem(bodyVelocity, vaultDuration)
task.wait(vaultDuration)

-- Apply speed boost
humanoid.WalkSpeed = humanoid.WalkSpeed + speedBoost
task.wait(0) -- Short duration for the speed boost
humanoid.WalkSpeed = humanoid.WalkSpeed - speedBoost

vaultCooldown = false

end

– Detect obstacles and trigger vault
game:GetService(“UserInputService”).InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.Space then – Press Space to vault
local ray = Ray.new(character.PrimaryPart.Position, character.PrimaryPart.CFrame.LookVector * 5)
local hit, position = workspace:FindPartOnRay(ray, character)

	if hit and isVaultable(hit) then
		performVault(hit)
	end
end

end)

1 Like