Prevent Double Key Inputs

Through some tutorials I was able to make a simple Fire Ball script; a bit sloppy but it works. When I added another input to fire a different fireball, or another skill, it seems you are able to press both keys and fire both remotes at the same time. I was thinking of a Boolean, but I wouldn’t know where to start. Maybe a way to wait at least a second before inputting another key would be helpful.

if example needed
(Use The tool to get the skills , then press E & R simultaneously.)

Prevent Double Key Input.rbxl (93.3 KB)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Remote = ReplicatedStorage.Events.FireBallEvent
local Remote2 = ReplicatedStorage.Events.FireBallEvent2
local Mouse = Plr:GetMouse()

local Debounce = true
local Animation = Instance.new("Animation")
Animation.AnimationId = 'rbxassetid://4805325052'

UIS.InputBegan:Connect(function(Inp, IsTyping)
	if IsTyping then return end
	if Inp.KeyCode == Enum.KeyCode.R and Debounce and Char then
		Remote2:FireServer(Mouse.Hit)
		Debounce = false
		script.RemoteEvent1:FireServer()
		local LoadAnimation = Char.Humanoid:LoadAnimation(Animation)
  		LoadAnimation:Play()
  		wait(10)
  		Debounce = true
	end
end)

UIS.InputBegan:Connect(function(Inp, IsTyping)
	if IsTyping then return end
	if Inp.KeyCode == Enum.KeyCode.E and Debounce and Char then
		Remote:FireServer(Mouse.Hit)
		Debounce = false
		script.RemoteEvent2:FireServer()
		local LoadAnimation = Char.Humanoid:LoadAnimation(Animation)
  		LoadAnimation:Play()
  		wait(6)
  		Debounce = true
	end
end)

You should store the data of whether or not they are already doing another skill on the server.

That server should be the one with that info so the client can’t manipulate doing multiple skills at one time. You can add a Boolean into the player (from the server) that can be used to check whether or not they are doing something. Set it up like a normal debounce, only it will be on the server script and you’re referencing an object in the Player.

2 Likes

Thank you, I didn’t think I was able to set the Boolean into the server