Securing RemoteEvents/Functions for a fighting game

Hello! Currently, I am working on a fighting game. Currently for example: I handle hit detection on the client but I handle things like:
“cutscene” attacks using RemoteEvents/Functions, and I want to make sure they’re safe.
Yes I’ve read some topics but I couldn’t find the key to make them at least a bit safe, thanks for any help!

Assuming this is for just some generic fighting game (swords, etc) you could apply the following techniques:

  • Distance check (Make sure they can actually hit the player)
  • Cooldown check (Are the hits being registered at an unrealistic interval?)
  • Raycast check (Is there anything in the way?)

Hmm, that could actually work! But should I do that on the client or the server?

Well if you did it on the client an exploiter could just “remove” your checks. You could of course continue to handle any effects on the client, but you want to make sure any important things are done on the server (damage, etc).

Alr, I’m really happy that I haven’t implemented the damage yet :sweat_smile:

Expanding on that first point @Jhxan made, here’s some ideas.

Given a scenario with two players fighting; let’s say “Player1” and “Player2,” you can use .Magnitude to check the distance (magnitude) between them. Magnitude simply means taking a vector and removing the directional part of it, leaving the magnitude. Think about a vector like an arrow (------> or <------); if you remove all direction, you’re left with a single line without an arrowhead pointing in any direction (------). Thus at that point, the “line” is just magnitude, or a value - it has no positive or negative correlation. Thus, when you get the distance between two vector points (be it Vector1, Vector2, or Vector3) you’re basically getting the absolute value of the vector - the distance, or magnitude, between the two points.

Going back to the example with Player1 and Player2, you can implement it something like this:

-- Run something like the below code when a player attacks another player

local magnitude = (player1.Position - player2.Position).Magnitude -- Distance in studs
if magnitude > 5 then -- If they're more than 5 studs apart
    -- Indicates cheating
    -- Indicates they're fine

And in case you’re interested in seeing how .Magnitude works behind the scenes more mathematically, here’s a post I made about it a while back: How does magnitude and range work? - #6 by MJTFreeTime

Also, you could check for teleporting players. I made a post on this a few weeks/months ago that includes a script I wrote that worked as a solution. Here it is if you’re interested: Dealing with teleporting in a fighting game? - #7 by MJTFreeTime

Hope this helps somewhat!

Thanks, and yeah I know about Magnitude for a long time, some time ago I needed to use that

1 Like