How to not "stack" moves?

Hello, I’m currently making a game with it’s a FFA, every move has a localscript which fires a RemoteEvent, etc.

I use a way with values which basically detects when a player is attacking or not, so they can’t use a move while executing another move.

My problem is, when a player presses two keys at same time (Example: Q and E), it executes both moves. How can I avoid this?.

1 Like

Just have a boolean and check if the player is attacking. If the player is currently using an attack or “move” then they can not do another “move” until the first one was completed.

1 Like

That’s what I do, however, when someone presses two times at same time, it executes both.

1 Like

Do you handle both inputs in separate scripts?

1 Like

I don’t know what you mean, but when a localscript executes the remote, the Value changes to false (meaning it can’t attack)

it changes once the Remote is executed, by server-side.

That would need to be in a loop though.

1 Like

That’s not exactly what I need, also remember every move have it’s own localscript, remote and cooldown.

1 Like

That is your issue. You should handle all input in the same local script. Plus you’ll run into an issue down the line when you have thousands of “moves”.

1 Like

About the thousands of “moves”, that’s not a problem because every “type” have like 3-6 moves.

Talking about the issue, Should I remake all localscripts into one then? and make a variable for each cooldown?

You should keep all of it in one local script in my opinion. Plus you never know when a type will have more than 3-6 moves.

My question is, it’s not the same as I do? Since i’m talking about pressing two keys at same time.

Here is what I am doing for my game that is similar to yours:

On the server, and the client I have modules for all the moves,

image

image

Example of how to set up the settings:
image

On the local script, I add all the modules to a table and require them if the key is the same as the module.

-- Load Modules
for i,v in pairs(script.Parent.PickElement:GetChildren()) do if v:IsA("TextButton") then
	v.MouseButton1Down:Connect(function()
			for i,v in pairs(script[Class.."Moves"]:GetChildren()) do
				table.insert(MoveModules,v)
			end
		end)
	end
end

-- Input (To Server)
UserInputService.InputBegan:Connect(function(key,chatting)
	if chatting or Move_Break then return end
	local BP = tostring(key.KeyCode) 
	local B = string.sub(BP, 14, string.len(BP))
	Move_Break = true delay(1,function() Move_Break = false end)
	for i,v in pairs(MoveModules) do
		local Move = require(v)
		if Move.Key == B then 
			local NewMove = require(v)
			NewMove.new(Player.Name, Move.Element, Move.Cooldown, Move.Stamina, Move.LastUsed, Mouse.Hit)
			NewMove:DoMove(Player.Name, Mouse.Hit, Mobile)
		end
	end
end)

On the server, I pass the arguments onto the serversided modules in order to do the stuff that is required to be on the server:

-- Load Modules
for i,v in pairs(script.AirMoves:GetChildren()) do
	table.insert(AirMoveModules,v)
end

-- Handle Moves (On Server)
MainE.OnServerEvent:Connect(function(Player, Element, Move, Mobile, Mouse, Side)
	if Element == "Air" then
		for i,v in pairs(AirMoveModules) do 
			if Move == v.Name then
				local NewMove = require(v)
				NewMove.new(Player.Name, NewMove.Element, NewMove.Cooldown, NewMove.Stamina, NewMove.LastUsed, Mouse)
				NewMove:DoMove(Player.Name, Mouse, Mobile, Side)
			end
		end
	end
end)

Move_Break prevents someone from firing two moves at once, which is what you originally asked for.

You can either do this or add all your moves into a LocalScript. I would not recommend creating a value as this is easily changed on the client.

That being said, if you want the simplest way to do this, just add a Move_Break variable to your function for getting input, this is what that would look like:

UserInputService.InputBegan:Connect(function(key,chatting)
	if chatting or Move_Break then return end
	Move_Break = true delay(1,function() Move_Break = false end)
end)
2 Likes

Okay, I would make all into a localscript, I don’t handle Modules very well but I will check what can I do, Thanks!.

It is a very daunting task, but once you get into it you realize it is not as complicated as it might seem.

Here is a helpful article on how you can use module scripts: