I have a damage script that uses remote events. I want to secure it so someone couldn't just constantly fire it to kill everyone. The scripts :
--local script
local attacking = false
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin and attacking == false then
attacking = true
local rs = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local name = player.Name
local o = name.."swordout"
local f = rs.PlayerStuff
local so = f:FindFirstChild(o)
so:FireServer()
script.Parent.Handle.SlashSound:Play()
wait(1)
attacking = false
end
end
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.Q)
--server script
local attacking = false
local rs = game:GetService("ReplicatedStorage")
local player = script.Parent.Parent.Parent.Character
local name = player.Name
local o = name.."swordout"
local f = rs.PlayerStuff
local so = f:FindFirstChild(o)
so.OnServerEvent:Connect(function()
attacking = true
local a = script.Parent.Basic
local h = player.Humanoid
local animTrack = h:LoadAnimation(a)
animTrack:Play()
wait(1)
attacking = false
end)
script.Parent.Handle.Touched:Connect(function (hit)
local h = hit.Parent
if h:FindFirstChild("Humanoid") and attacking == true then
local hum = h.Humanoid
local dmg = script.Parent.Damage.Value
hum:TakeDamage(dmg)
attacking = false
end
end)
I was thinking about using a distancefromcharacter, but that wouldn't work because they'd just have to walk up to someone. What should I do to secure this?

2 comments
I've edited my post to what you said to do. COuldn't someones till constantly fire the so event to keep the debounce true so they just have to touch the person and not be attacking to damage them?
That would be the equivalent of them mashing a key button on their keyboard. If you don't want this to be a good option for players, consider adding a wait time for when they can activate their attack again (a second debounce).