So, I was making a punching script, but there’s an error that keeps occuring, which I have no idea how to fix.
Here’s the script:
local animations = script.Animations
local KeyProvider = game:GetService("KeyframeSequenceProvider")
local Combat_Handler=
{
MeleeAnims = {
["L"] = animations.Melee1,
["LL"] = animations.Melee2,
["LLL"] = animations.Melee3,
["LLLL"] = animations.Melee4
},
}
function Combat_Handler.getAnimation(Humanoid, sequence)
local length = 0
local keysequence = KeyProvider:GetKeyframeSequenceAsync(Combat_Handler,animations[sequence].AnimationID)
local keyframes = keysequence:GetKeyframes()
for i=1, #keyframes do
local Time = keyframes[i].Time
if Time > length then
length = time()
end
end
return Humanoid.Animator:LoadAnimation(Combat_Handler.MeleeAnims[sequence]), length
end
return Combat_Handler
Here’s the error,
09:28:30.247 ServerScriptService.CombatServer.Combat_Handler:23: attempt to index nil with ‘sequence’ - Server - Combat_Handler:23
Your script is finding the “sequence” as nil. Double check that everything is working with it, and step by step debug your code using print statements:
Example:
function Chicken(chicken1, chicken2)
print("the function fired")
if chicken1.Name == "idk" then
print("first if check")
end
end
Try doing this to locate the part in which is throwing the error, and from there, you can debug it with ease!
I think I found your error, unless this is intentional:
local sequence = ""
local curr = 0
local prev = 0
UIS.InputBegan:Connect(function(input, isTyping)
if not isTyping then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if debounce == false then
debounce = true
curr = os.clock()
local PT = curr - prev
if PT < 1 then
sequence = sequence.."L"
if string.len("sequence") > 4 then
sequence = "L"
end
else
sequence = "L"
end
Combat:FireServer("sequence")
end
end
end
end)
Combat:FireServer(“sequence”) is only returning a string named sequence. From what I’ve briefly seen, your script is checking for animations, none of which relate to this string directly. Did you mean to say
Combat:FireServer(sequence)?
Sure, 10:16:12.667 ServerScriptService.CombatServer.Combat_Handler:23: attempt to index nil with ‘L’ - Server - Combat_Handler:23, I also attached a copy earlier, it’s in a module script.
This is the module script:
local animations = script.Animations
local KeyProvider = game:GetService("KeyframeSequenceProvider")
local Combat_Handler=
{
MeleeAnims = {
["L"] = animations.Melee1,
["LL"] = animations.Melee2,
["LLL"] = animations.Melee3,
["LLLL"] = animations.Melee4
},
}
function Combat_Handler.getAnimation(Humanoid, sequence)
local length = 0
local keysequence = KeyProvider:GetKeyframeSequenceAsync(Combat_Handler.Animations[sequence].AnimationID)
local keyframes = keysequence:GetKeyframes()
for i=1, #keyframes do
local Time = keyframes[i].Time
if Time > length then
length = time()
end
end
return Humanoid.Animator:LoadAnimation(Combat_Handler.MeleeAnims[sequence]), length
end
return Combat_Handler