Hi,
Recently, I’ve been working on my Leap of Faith system trying to hone my skill at LUA, but I’ve encountered an issue with this script.
I believe it has something to do with my i, v in pairs loop. I have 4 hay stacks in my workspace and the script repeats 5 times, and increases when adding another hay.
Here is a gif provided below for context, as well as the script.
https://gyazo.com/ae7f8baa0468fc84b6ec1a7eedf5025f.gif
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
repeat wait() until character:FindFirstChild("Humanoid")
local BezierTween = require(script.BezierTweens)
local debounce = false
local noFallDamageTime = 8
-- Loading Animations
local LoFS = character.Humanoid:LoadAnimation(script.LoFStart)
local LoFSBack = character.Humanoid:LoadAnimation(script.LoFBackflip)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
if debounce == true then return end
debounce = true
-- Looping through the hays and comparing positions
for i, v in pairs(game.Workspace.Hays:GetChildren()) do
local HeightCalc = character:WaitForChild("HumanoidRootPart").Position.Y - v.Position.Y
print(HeightCalc.."!!!!!!!!!!!!!!!")
local HeightMag = (player.Character.HumanoidRootPart.Position.Y - v.Position.Y)
local DistanceMag = (player.Character.HumanoidRootPart.Position.Z - v.Position.Z) + (player.Character.HumanoidRootPart.Position.X - v.Position.X)
local DistanceMag1 = math.abs(DistanceMag)
print(HeightMag.."HEIGHT !!!!!!!!!!!!!")
print(DistanceMag1.." DISTANCE !!!!!!!!!!!!!!!!")
if DistanceMag1 <= 40 and HeightMag >= 50 then
if debounce == true then return end
debounce = true
script.NoFallDMG:FireServer(6)
script.Leap:Play()
script.Air:Play()
local Curve1Part = Instance.new("Part")
Curve1Part.Position = Vector3.new(v.Position.X,character.HumanoidRootPart.Position.Y + 30,v.Position.Z) -- add 30 to give it a dive
Curve1Part.Anchored = true
Curve1Part.Name = "BezierCurvePart"
Curve1Part.Parent = v
Curve1Part.Size = Vector3.new(4,4,4)
Curve1Part.CanCollide = false
Curve1Part.Transparency = 1
game.Debris:AddItem(Curve1Part, 5)
local Curve2Part = Instance.new("Part")
Curve2Part.Position = Vector3.new(character.HumanoidRootPart.Position.X, character.HumanoidRootPart.Position.Y, character.HumanoidRootPart.Position.Z)
Curve2Part.Anchored = true
Curve2Part.Name = "BezierCurvePart2"
Curve2Part.Parent = v
Curve2Part.Size = Vector3.new(4,4,4)
Curve2Part.CanCollide = false
Curve2Part.Transparency = 1
Curve2Part.Parent = v
game.Debris:AddItem(Curve2Part, 5)
local function QuadraticBezier(t,p0,p1,p2)
return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2;
end;
local primaryPart = character.PrimaryPart
local originalorientation = character.HumanoidRootPart.Orientation
local initial = character.HumanoidRootPart.Position
print(character.Head.CFrame.LookVector)
local lookDot = (v.Position - character.Head.Position).Unit
local lookDot1 = character.Head.CFrame.LookVector
local dotProduct = lookDot:Dot(lookDot1)
print(dotProduct)
spawn(function()
if dotProduct <= -0.2 then
print("backflip")
LoFSBack:Play()
LoFSBack:AdjustSpeed(1.7)
else
LoFS:Play()
LoFS:AdjustSpeed(1.7)
end
for t = 0,1,0.01 do
character.Humanoid:UnequipTools()
local TargetPosition = QuadraticBezier(t , character.HumanoidRootPart.Position, Curve1Part.Position, v.Position);
character.HumanoidRootPart.CFrame = (CFrame.new(QuadraticBezier(t, initial, Curve1Part.Position, v.Position))) * CFrame.fromEulerAnglesXYZ(math.rad(originalorientation.X), (math.rad(originalorientation.Y)), math.rad(originalorientation.Z))--CFrame.Angles(originalorientation.X, originalorientation.Y, originalorientation.Z)
game:GetService("RunService").Heartbeat:Wait()
if t >= 0.8 then
script.Air:Stop()
end
if t >= 0.95 then
--debounce = false
script.Hay:Play()
wait(2)
debounce = false
end
end;
end)
wait(5)
--debounce = false
else
--wait(2)
debounce = false
end
end
end
end)