Hi so I'm currently working on a basic fist combat system, I've gotten pretty far to the point where the player can swing and damage with their fists, however, there's an issue within my server script.
I used two variables in my serverscript to detect when the arms should deal damage.
1 | leftDamage = false |
2 | rightDamage = false |
However, when a player swings with their left arm for example, yes their left arm will deal damage, but so will everybody in the games.
I'm just going to include all the code here, sorry if what I've included is unnecessary
01 | local repStorage = game:GetService( "ReplicatedStorage" ) |
02 | local remoteEvent = repStorage:WaitForChild( "Swing" ) |
03 | Players = game:GetService( "Players" ) |
04 | leftDamage = false |
05 | rightDamage = false |
06 | char = script.Parent.Parent |
07 | char:WaitForChild( "Humanoid" ) |
08 | leftarm = char:WaitForChild( "Left Arm" ) |
09 | rightarm = char:WaitForChild( "Right Arm" ) |
10 |
11 |
12 |
13 | remoteEvent.OnServerEvent:connect( function (player, passthrough) |
14 | local char = player.Character |
15 | if passthrough = = "L" then |
If I am able to interpret this correctly, you have a server script in each character.
When the remote event is fired, your script doesn't check if the player who is firing it owns the character model. As a result, when it is fired, all server scripts with this code will set rightDamage or leftDamage to true, indiscriminate of who fired the event originally.
By adding something like if player.Character == char
to the remote event's associated function, then you could prevent this from happening.
The solution is that the script checks if the name of the player who was hit was equivalent to the player attacking
01 | local repStorage = game:GetService( "ReplicatedStorage" ) |
02 | local remoteEvent = repStorage:WaitForChild( "Swing" ) |
03 | Players = game:GetService( "Players" ) |
04 | leftDamage = false |
05 | rightDamage = false |
06 | char = script.Parent.Parent |
07 | char:WaitForChild( "Humanoid" ) |
08 | leftarm = char:WaitForChild( "Left Arm" ) |
09 | rightarm = char:WaitForChild( "Right Arm" ) |
10 |
11 |
12 |
13 | remoteEvent.OnServerEvent:connect( function (player, passthrough) |
14 | local char = player.Character |
15 | if passthrough = = "L" then |
New script, Put this in the tool directly and not in handles or parts.
01 | local repStorage = game:GetService( "ReplicatedStorage" ) |
02 | local remoteEvent = repStorage:WaitForChild( "Swing" ) |
03 | Players = game:GetService( "Players" ) |
04 | leftDamage = false |
05 | rightDamage = false |
06 | char = script.Parent.Parent |
07 | char:WaitForChild( "Humanoid" ) |
08 | leftarm = char:WaitForChild( "Left Arm" ) |
09 | rightarm = char:WaitForChild( "Right Arm" ) |
10 |
11 |
12 |
13 | remoteEvent.OnServerEvent:connect( function (player, passthrough) |
14 | local char = player.Character |
15 | if passthrough = = "L" then |