Making it so when the player holds down a key, it will charge up a move and then when they release it the move will fire

Hi! I am trying to make it so that the player can hold down a key for however long they want, and then when they release the key, the move will fire.

At the moment I have been trying to adapt a piece of code from a tutorial I found, as I am still learning scripting. The move, at the moment, will fire when the player simply taps the key. This is my code at the moment:

--
UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.F and Debounce == true and Tool.Equip.Value == true and Tool.Active.Value == "None" then
		Debounce = false
		Tool.Active.Value = "Fireball"
		wait(0.1)
		wait(0.15)
		script.Fire:FireServer(plr)
	local hum =  Player.Character.Humanoid
	for i = 1,30 do
		wait()
		hum.CameraOffset = Vector3.new(
			math.random(-0,0),
			math.random(-0,0),
			math.random(-0,0)
		)
	end
	hum.CameraOffset = Vector3.new(0,0,0)
	    wait(0.15)
		Tool.Active.Value = "None"
		wait(2)
		Debounce = true
	end
end)

A good example of what I’m trying to create can be found in a game called King Legacy:


Here the player can charge up the move and then release by not holding down the key anymore.

I have tried looking all over the internet for this and I couldn’t really find anything. This is my first time posting on this website, so I’m very sorry if I get some things wrong. Thanks!

1 Like

Here is the link that will help you with this

IsKeyDown

Use uis.InputBegan and uis.InputEnded. Can’t elaborate much cuz on phone rn but input began fires whenever the user presses a key and input ended fires whenever the user takes up a key.

No??? It can only be used to check if a key is down at the current time, and not if the key went up or down. U didn’t understand his question properly.

3 Likes

You can follow this tutorial . this is a playlist of how to make sword combat system and as you have said the charge up move tutorial is also there . Hope this helps

He is saying how to make it only fires if it is charged .

Hey! Sorry if what I said in the main post was confusing. What i’m trying to make is so the player can hold down the key for however long they want, not for a charge-up. In the video I posted, what I was doing was just holding down the key and when I let it go the move fired and there was no set amount of time it took for the charge up to happen, which technically means that in the game you could have just tapped the key and it would have fired. Sorry for the confusion!

1 Like