local Animations = {
Reload = function(S) --This is the main reload animation. The parameter S contains all the variables and functions that are necessary for this animation
local W1 = nil
local W2 = nil
local animSpeed = S.isMagEmpty() and S.reloadTimeEmpty / 1.3 or S.reloadTimeLoaded / 0.9
local Ammunition = script.Parent.Ammo.Value
local ClipSize = script.Parent.ClipSize.Value
local AmmoNeeded = ClipSize - Ammunition - 2
return {
function()
if (not S.isNewMag()) then
if S.isMagVisible() then
local Mag1, magTable1 = S.createMag("Mag1")
Mag1.Parent = S.gunIgnore
W1 = Instance.new("Weld")
W1.Part0 = magTable1[1].magClone
W1.Part1 = S.Handle
W1.C0 = magTable1[1].Original.CFrame:toObjectSpace(S.Handle.CFrame)
W1.Parent = magTable1[1].magClone
S.tweenJoint(S.LWeld, nil, S.CF(0.58, 1.63, -1.4) * S.CFANG(S.RAD(90), 0, S.RAD(-60)), S.Sine, 0.2 * animSpeed)
S.tweenJoint(S.RWeld, nil, S.CF(0.3, 0.2, -0.51) * S.CFANG(S.RAD(-12), 0, S.RAD(25)), S.Sine, 0.2 * animSpeed)
S.tweenJoint(S.Grip, nil, S.CFANG(0, S.RAD(20), S.RAD(10)), S.Sine, 0.1 * animSpeed)
wait(0.2 * animSpeed)
end
end
end;
function()
if (not S.isNewMag()) then
if S.isMagVisible() then
S.makeMagInvisible()
W1:Destroy()
local Mag1, magTable1 = S.getMag("Mag1")
magTable1[1].magClone.Velocity = S.Handle.Velocity + S.Handle.CFrame:vectorToWorldSpace(S.V3(0, -1, 0)) * 20
S.tweenJoint(S.Grip, nil, S.CFANG(0, S.RAD(20), S.RAD(10)), S.Sine, 0.2 * animSpeed)
else
S.tweenJoint(S.Grip, nil, S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10)), S.Sine, 0.2 * animSpeed)
end
S.tweenJoint(S.LWeld, nil, S.CF(0, 0.5, 0) * S.CFANG(S.RAD(95), 0, S.RAD(-25)), S.Sine, 0.2 * animSpeed)
wait(0.25 * animSpeed)
end
end;
-- -- -- -- ERROR HERE -- on 'if' it says Expected identifier, got 'if'
if AmmoNeeded < 0 then
repeat
function()
if (not S.isNewMag()) then
local Mag1, magTable1 = S.getMag("Mag1")
if Mag1 then Mag1:Destroy() end
local Mag2, magTable2 = S.createMag("Mag2")
Mag2.Parent = S.gunIgnore
local LArmCF = S.LWeld.Part0.CFrame * S.LWeld.C0 * (S.CF(0.58, 1.63, -1.4) * S.CFANG(S.RAD(-22), S.RAD(20), S.RAD(-60))):inverse()
local RArmCF = S.RWeld.Part0.CFrame * S.RWeld.C0 * (S.CF(0.6, 0.2, -0.61) * S.CFANG(S.RAD(-15), S.RAD(20), S.RAD(25))):inverse()
local handleOffsetCF = S.RArm.CFrame:toObjectSpace(S.RArm.CFrame * S.Grip.C0 * (S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10))):inverse())
local originalMagOffsetCF = S.Handle.CFrame:toObjectSpace(magTable2[1].Original.CFrame)
local newMagC0 = LArmCF:toObjectSpace(RArmCF * handleOffsetCF * originalMagOffsetCF)
W2 = Instance.new("Weld")
W2.Part0 = S.LArm
W2.Part1 = magTable2[1].magClone
W2.C0 = newMagC0
W2.Parent = magTable2[1].magClone
S.tweenJoint(S.LWeld, nil, S.CF(0.55, 0.6, -2.4) * S.CFANG(S.RAD(-20), S.RAD(20), S.RAD(-60)), S.Sine, 0.2 * animSpeed)--0.25
S.tweenJoint(S.RWeld, nil, S.CF(0.6, 0.2, -0.61) * S.CFANG(S.RAD(-12), S.RAD(20), S.RAD(25)), S.Sine, 0.2 * animSpeed)
S.tweenJoint(S.Grip, nil, S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10)), S.Sine, 0.2 * animSpeed)
wait(0.2 * animSpeed)
end
end;
function()
if (not S.isNewMag()) then
S.tweenJoint(S.Grip, nil, S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10)), S.Sine, 0.15 * animSpeed)
S.tweenJoint(S.LWeld, nil, S.CF(0.58, 1.63, -1.4) * S.CFANG(S.RAD(-22), S.RAD(20), S.RAD(-60)), S.Sine, 0.15 * animSpeed)--0.25
S.tweenJoint(S.RWeld, nil, S.CF(0.6, 0.2, -0.61) * S.CFANG(S.RAD(-15), S.RAD(20), S.RAD(25)), S.Sine, 0.2 * animSpeed)
script.Parent.Handle.MagIn:Play()
wait(0.2 * animSpeed)
end
end;
function()
if (not S.isNewMag()) then
if S.isMagVisible() then
S.makeMagInvisible()
W1:Destroy()
local Mag1, magTable1 = S.getMag("Mag1")
magTable1[1].magClone.Velocity = S.Handle.Velocity + S.Handle.CFrame:vectorToWorldSpace(S.V3(0, -1, 0)) * 20
S.tweenJoint(S.Grip, nil, S.CFANG(0, S.RAD(20), S.RAD(10)), S.Sine, 0.2 * animSpeed)
else
S.tweenJoint(S.Grip, nil, S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10)), S.Sine, 0.2 * animSpeed)
end
S.tweenJoint(S.LWeld, nil, S.CF(0, 0.5, 0) * S.CFANG(S.RAD(95), 0, S.RAD(-25)), S.Sine, 0.2 * animSpeed)
wait(0.25 * animSpeed)
AmmoNeeded = AmmoNeeded - 1
end
end;
until AmmoNeeded = 0
end
-- -- --
function()
if (not S.isNewMag()) then
local Mag1, magTable1 = S.getMag("Mag1")
if Mag1 then Mag1:Destroy() end
local Mag2, magTable2 = S.createMag("Mag2")
Mag2.Parent = S.gunIgnore
local LArmCF = S.LWeld.Part0.CFrame * S.LWeld.C0 * (S.CF(0.58, 1.63, -1.4) * S.CFANG(S.RAD(-22), S.RAD(20), S.RAD(-60))):inverse()
local RArmCF = S.RWeld.Part0.CFrame * S.RWeld.C0 * (S.CF(0.6, 0.2, -0.61) * S.CFANG(S.RAD(-15), S.RAD(20), S.RAD(25))):inverse()
local handleOffsetCF = S.RArm.CFrame:toObjectSpace(S.RArm.CFrame * S.Grip.C0 * (S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10))):inverse())
local originalMagOffsetCF = S.Handle.CFrame:toObjectSpace(magTable2[1].Original.CFrame)
local newMagC0 = LArmCF:toObjectSpace(RArmCF * handleOffsetCF * originalMagOffsetCF)
W2 = Instance.new("Weld")
W2.Part0 = S.LArm
W2.Part1 = magTable2[1].magClone
W2.C0 = newMagC0
W2.Parent = magTable2[1].magClone
S.tweenJoint(S.LWeld, nil, S.CF(0.55, 0.6, -2.4) * S.CFANG(S.RAD(-20), S.RAD(20), S.RAD(-60)), S.Sine, 0.2 * animSpeed)--0.25
S.tweenJoint(S.RWeld, nil, S.CF(0.6, 0.2, -0.61) * S.CFANG(S.RAD(-12), S.RAD(20), S.RAD(25)), S.Sine, 0.2 * animSpeed)
S.tweenJoint(S.Grip, nil, S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10)), S.Sine, 0.2 * animSpeed)
wait(0.2 * animSpeed)
end
end;
function()
if (not S.isNewMag()) then
S.tweenJoint(S.Grip, nil, S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10)), S.Sine, 0.15 * animSpeed)
S.tweenJoint(S.LWeld, nil, S.CF(0.58, 1.63, -1.4) * S.CFANG(S.RAD(-22), S.RAD(20), S.RAD(-60)), S.Sine, 0.15 * animSpeed)--0.25
S.tweenJoint(S.RWeld, nil, S.CF(0.6, 0.2, -0.61) * S.CFANG(S.RAD(-15), S.RAD(20), S.RAD(25)), S.Sine, 0.2 * animSpeed)
script.Parent.Handle.MagIn:Play()
wait(0.2 * animSpeed)
end
end;
function()
if (not S.isNewMag()) then
local Mag1, _ = S.getMag("Mag1")
local Mag2, _ = S.getMag("Mag2")
S.makeMagVisible()
S.setNewMag()
if Mag1 then Mag1:Destroy() end
Mag2:Destroy()
end
end;
function()
if S.isMagEmpty() then
if S.isNewMag() then
S.tweenJoint(S.Grip, nil, S.CFANG(S.RAD(-10), S.RAD(20), S.RAD(10)), S.Sine, 0.15 * animSpeed)
S.tweenJoint(S.LWeld, nil, S.CF(0.58, 1.63, -1.4) * S.CFANG(S.RAD(-22), S.RAD(20), S.RAD(-60)), S.Sine, 0.15 * animSpeed)--0.25
S.tweenJoint(S.RWeld, nil, S.CF(0.6, 0.2, -0.61) * S.CFANG(S.RAD(-15), S.RAD(20), S.RAD(25)), S.Sine, 0.2 * animSpeed)
end
S.tweenJoint(S.LWeld, nil, S.CF(0.2, 1.9, -0.45) * S.CFANG(S.RAD(-23), 0.1, S.RAD(-40)), S.Sine, 0.1 * animSpeed)
wait(0.4 * animSpeed)
end
end;
function()
if S.isMagEmpty() then
S.tweenJoint(S.LWeld, nil, S.CF(-0.2, 1.7, -0.45) * S.CFANG(S.RAD(-23), 0.1, S.RAD(-40)), S.Sine, 0.1 * animSpeed)
script.Parent.Handle.Prime:Play()
wait(0.3 * animSpeed)
end
end;
function()
if S.isMagEmpty() then
S.tweenJoint(S.LWeld, nil, S.CF(0.2, 1.9, -0.45) * S.CFANG(S.RAD(-23), 0.1, S.RAD(-40)), S.Sine, 0.1 * animSpeed)
wait(0.3 * animSpeed)
end
end;
}
end;
Line 56 has the error. Thanks to some people, I've realised that the error lies within the fact that I can't exactly return an if statement to a table - 'cos it's a returning function. But the goal of the if statement was to repeat a function a certain amount of times, which can vary depending on outside values. So help would be appreciated if you can help me do that.
Thank you!
N.B. Most of the code after line 119 is not needed to solve the problem.

2 comments
you could do <= 1
Unfortunately, that's not the problem, and since it's always integers, there was no need.