I am making a vault script for my game, but for some reason it breaks after about 6 uses. How can I fix this?
script:
local Thing1 = script.Parent.Parent.Thing1
local Thing2 = script.Parent.Parent.Thing2
local prompt = script.Parent.ProximityPrompt
local TweenService = game:GetService("TweenService")
local Vaulting = false
local tweenInfo = TweenInfo.new(
1
)
prompt.Triggered:Connect(function(player)
if Vaulting == false then
Vaulting = true
prompt.Enabled = false
print("Valut!")
local Magnitude1 = (player.Character.HumanoidRootPart.Position - Thing1.Position).Magnitude
local Magnitude2 = (player.Character.HumanoidRootPart.Position - Thing2.Position).Magnitude
if Magnitude1 < Magnitude2 then
player.Character.HumanoidRootPart.CFrame = Thing1.CFrame
game.ReplicatedStorage.Gameplay.WVault:FireAllClients()
local tween = TweenService:Create(player.Character.HumanoidRootPart, tweenInfo, {Position = Thing2.Position}):Play()
wait(1)
Vaulting = false
prompt.Enabled = true
elseif Magnitude2 < Magnitude1 then
player.Character.HumanoidRootPart.CFrame = Thing2.CFrame
game.ReplicatedStorage.Gameplay.WVault:FireAllClients()
local tween = TweenService:Create(player.Character.HumanoidRootPart, tweenInfo, {Position = Thing1.Position}):Play()
wait(1)
Vaulting = false
prompt.Enabled = true
end
end
end)