Help with a combat system

hello,

i was making an M1 system and i ran into an issue.

local UIS = game:GetService("UserInputService")
local attacknum = 0
local Mscript = script.Parent.testimgm1m
local debounce = false
local newtick = nil
local ticktime = nil

UIS.InputBegan:Connect(function(input, istyping)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not istyping and debounce == false then
	--first punch
	if attacknum == 0 then
		debounce = true
		require(Mscript).punch1()
		wait(0.5)
		debounce = false
		ticktime = tick()
	end
	--timeout punch 2
	elseif attacknum == 1 then
		newtick = tick()
		if newtick - ticktime > 1.5 then
		debounce = true
		require(Mscript).punch1()
		attacknum = 0
		wait(0.5)
		debounce = false
		ticktime = tick()
		end
	end
	--timed punch 2
	if attacknum == 1 then
		newtick = tick()
		if newtick - ticktime <= 1.5 then
		debounce = true
		require(Mscript).punch2()
		attacknum = 2
		wait(0.5)
		debounce = false
		ticktime = tick()
		
	end
	--timeout punch 3
	elseif attacknum == 2 then
		newtick = tick()
		if newtick - ticktime > 1.5 then
		debounce = true
		require(Mscript).punch1()
		attacknum = 0
		wait(0.5)
		debounce = false
		ticktime = tick()
		end
	end	
	--timed punch 3
	if attacknum == 2 then
		newtick = tick()
		if newtick - ticktime <= 1.5 then
		debounce = true
		require(Mscript).punch3()
		attacknum = 3
		wait(0.5)
		debounce = false
		ticktime = tick()
	end
	--timeout punch 4
	elseif attacknum == 3 then
		newtick = tick()
		if newtick - ticktime > 1.5 then
		debounce = true
		require(Mscript).punch1()
		attacknum = 0
		wait(0.5)
		debounce = false
		ticktime = tick()
		end
	end
	--timed punch 4
	if attacknum == 3 then
		newtick = tick()
		if newtick - ticktime <= 1.5 then
		debounce = true
		require(Mscript).punch4()
		attacknum = 0
		wait(1)
		debounce = false
			
		end	
	end	
end)

my script is designed to do a series of 4 punches, in a row. if you punch again, after the first punch, iwthin 1.5 seconds, it will go to the next punch. if you punch later than that, you go back to the first punch.

so, it will basicly just do the first punch over and over.
thats my problem. what am i doing wrong?

1 Like

In this piece of code, you never increased attacknum by 1 at all. That just means your looping through the entire thing again each time. Try adding attacknum = 1, and hopefully it doesn’t repeat again.

ok, that worked, but i ran into another problem. thank you btw. whenever i click, it does every punch one after another, upon being clicked once. for example:

it should be:
click
punch1
click
punch2
click
punch 3
click
punch4

instead, its
click
punch1
punch2
punch3
punch4

what part of my code is causing this error?

1 Like

ill just create a new topic ig…

1 Like

perhaps posting your new script might help,

and also you prob need to keep track of what was the last punch, , if click again, less then time limit, then move on to next punch, if time was greater then limit, do first punch, record punch…

instead of looping it…

you main code is looking for one click, then going through all the punches, you need to do one check for a click and one check (although it seems the elseif s should not be entered if one is done… but… prob something to do with above)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.