Mech Punching Script

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

1 Like

how do u want it to work??? and say what its showing

Hiya!
In order to assist you, we need to know what is calling upon your function, and what the “sequence” is actually returning! Thanks!

It’s just running an animation, there isn’t a damaging script yet. It just shows up this error, saying the sequence piece is an error.

1 Like

Sequence, is returning a set, that is connected to how many times the player clicks their left mouse button, which is stored in a module.

I can give a copy of the game if that helps out.

Here’s the copy:
share.rbxl (336.6 KB)

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!

Nope, there doesn’t seem to be anything wrong with the script, I even used script analysis, but still there’s no script problem.

1 Like

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)?

Hm, that might be it. Let me test it out.

Now it’s saying attempted to index nil with L. I’m a bit busy rn, so I’ll check around some more in a bit.

Which script? And where? Mind showing me the output?

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

1 Like

i think it means that there is no animations whose name is “L”.

Oh, the l was used as a kind of way to count. I’ll change that and see if it works.

1 Like

DId it work? if it worked then marking the solution would be better

1 Like

No it hasn’t sorry I forgot to say that, I was a bit busy with other matters.