Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I secure my damage remote events?

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

✓ Accepted answer

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.

2 comments

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?

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).

This discussion is preserved as it was. New answers, comments, and votes are closed.