Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Melee tool not working on a certain line?

INFORMATION: I was working on a melee tool for a while now, everything was going smoothly until I wanted to make it where if the player jumps and presses q in a certain time they will do an overhead attack that will do stuff later on, but while scripting it, nothing prints, can I get some help?

PROBLEM: (What I presume) The script gets to a certain point and the script and freezes/stops and does not print anything.

SCRIPT:

-- change variable when player jumps 
character.Humanoid.Jumping:Connect(function()
	jumping = true
end)
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		if toolEquipped == false then return end;
		if kicking or guarding or usingSpeical == true then return end;
		if not punching then
			punching = true
			
			-- overhead
			if jumping == true then
				if tick()-timer < 0.15 then
					print("overhead")
					wait(0.5)
					punching = false
				end
				timer = tick()
				
			else
				if tick()-timer > 2 then
					punchAnimation = 0
				end
				timer = tick()
				
				punchAnimation = punchAnimation + 1
				local ActionAnimation = character.Humanoid:LoadAnimation(replicatedStorage.Animations["MeleePunch"..punchAnimation])
				ActionAnimation:Play()
				actions.Punch:InvokeServer(punchAnimation)
				
				if punchAnimation >= 2 then
					punchAnimation = 0
				end
			end
		end)

Any help would be greatly appreciated!

1 answer

the reason is that you set punching to true but then only set it back to false if your combo triggered. The first time it likely did not because you were either not jumping or not pressing q twice within .15 seconds, which is rather stringent. From then on indeed the script locks and doesn't pass "if not punching then" on line 5 of the second script anymore

To solve move "punching = false" to the end of the mentioned if statement, so between line 31-32 (your example code is missing some 'end's here, prob from copy pasting).

2 comments

0

actually you couldnt have triggered it even if you're careful because the first time would have set it to false and only the second time can trigger the combo....

0

and in general i suggest moving duplicate code out of the if-else statement, such as "timer = tick()"

This discussion is preserved as it was. New answers, comments, and votes are closed.