Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I secure my damage remote events?

Asked by
Viking359 161
6 years ago
Edited 6 years ago

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?

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
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? Viking359 161 — 6y
0
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). User#18718 0 — 6y
Ad

Answer this question