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

FE Fist combat system issues, both players take damage?

Asked by 5 years ago
Edited 5 years ago

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.

1leftDamage = false
2rightDamage = 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

01local repStorage = game:GetService("ReplicatedStorage")
02local remoteEvent = repStorage:WaitForChild("Swing")
03Players = game:GetService("Players")
04leftDamage = false
05rightDamage = false
06char = script.Parent.Parent
07char:WaitForChild("Humanoid")
08leftarm = char:WaitForChild("Left Arm")
09rightarm = char:WaitForChild("Right Arm")
10 
11 
12 
13remoteEvent.OnServerEvent:connect(function(player, passthrough)
14local char = player.Character
15    if passthrough == "L" then
View all 47 lines...
0
I have a solution im just writing it out Dec_ade 47 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

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.

0
im not sure where im putting this but i havent had any luck with it so far BIuehawks 62 — 5y
0
The remote event on line 13 fires for all versions of the serverscript, in every character. You need to make sure that its only setting the damage arm to true for the character who actually swung, so you need to include a logic statement. IStarConquestI 414 — 5y
Ad
Log in to vote
0
Answered by
Dec_ade 47
5 years ago
Edited 5 years ago

The solution is that the script checks if the name of the player who was hit was equivalent to the player attacking

01local repStorage = game:GetService("ReplicatedStorage")
02local remoteEvent = repStorage:WaitForChild("Swing")
03Players = game:GetService("Players")
04leftDamage = false
05rightDamage = false
06char = script.Parent.Parent
07char:WaitForChild("Humanoid")
08leftarm = char:WaitForChild("Left Arm")
09rightarm = char:WaitForChild("Right Arm")
10 
11 
12 
13remoteEvent.OnServerEvent:connect(function(player, passthrough)
14local char = player.Character
15    if passthrough == "L" then
View all 49 lines...
0
This should work i think Dec_ade 47 — 5y
0
no luck BIuehawks 62 — 5y
0
OOF Dec_ade 47 — 5y
Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
5 years ago
Edited 5 years ago

New script, Put this in the tool directly and not in handles or parts.

01local repStorage = game:GetService("ReplicatedStorage")
02local remoteEvent = repStorage:WaitForChild("Swing")
03Players = game:GetService("Players")
04leftDamage = false
05rightDamage = false
06char = script.Parent.Parent
07char:WaitForChild("Humanoid")
08leftarm = char:WaitForChild("Left Arm")
09rightarm = char:WaitForChild("Right Arm")
10 
11 
12 
13remoteEvent.OnServerEvent:connect(function(player, passthrough)
14local char = player.Character
15    if passthrough == "L" then
View all 47 lines...
0
It's in startercharacterscripts but I'll try it anyways BIuehawks 62 — 5y
0
sadly not sorry BIuehawks 62 — 5y

Answer this question