When I was testing my gun, it damaged me than the person that I was shooting, Why? Any way to fix it?
Gun script:
01 | local debounce = false |
02 | script.Parent.Parent.Equipped:Connect( function (mouse) |
03 | mouse.Button 1 Down:Connect( function (idk) |
04 | if debounce then else |
05 | ******************:FireServer(mouse.Target.Parent) |
06 | debounce = true |
07 | wait( 1 ) |
08 | debounce = false |
09 | end |
10 | end ) |
11 | end ) |
RemoteEvent script:
1 | script.Parent.OnServerEvent:Connect( function (key) |
2 | if workspace [ key.Name ] :FindFirstChild( "Humanoid" ) then |
3 | workspace [ key.Name ] .Humanoid:TakeDamage( 10 ) |
4 | end |
5 | end ) |
Thank you in advance!
Your issue is on line 1 of the remote event script. When talking from client to server the first parameter passed is the player who actually fired the server. So it's reading Key as yourself because it's in the first parameter's position. The fix is easy. Change the first line to this instead:
1 | script.Parent.OnServerEvent:Connect( function (plr, key) |