When I was testing my gun, it damaged me than the person that I was shooting, Why? Any way to fix it?
Gun script:
local debounce = false script.Parent.Parent.Equipped:Connect(function(mouse) mouse.Button1Down:Connect(function(idk) if debounce then else ******************:FireServer(mouse.Target.Parent) debounce = true wait(1) debounce = false end end) end)
RemoteEvent script:
script.Parent.OnServerEvent:Connect(function(key) if workspace[key.Name]:FindFirstChild("Humanoid") then workspace[key.Name].Humanoid:TakeDamage(10) end 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:
script.Parent.OnServerEvent:Connect(function(plr, key)