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?
Move your Touched event of the handle to the server. You already do some of this with the "swordout" remoteevent. That way you can remove the damage remote event.