Hello, i have a script that deals damage whenever i hit F, like throws a punch and deals damage, the problem is that if there are 2 or more players, if 1 player presses F and punches, the other players can`t, how can i fix it ?
Local script in starterPlayerScripts :
local UIS = game:GetService('UserInputService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local remotePunch = replicatedStorage:WaitForChild('Punch')
UIS.InputBegan:connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.F then
remotePunch:FireServer()
end
end)
Script for system in serverscriptservice :
local replicatedStorage = game:GetService('ReplicatedStorage')
local PunchingRemote = replicatedStorage:WaitForChild('Punch')
local anim1 = Instance.new('Animation')
local anim2 = Instance.new('Animation')
anim1.AnimationId = 'http://www.roblox.com/asset/?id=6985138442'
anim2.AnimationId = 'http://www.roblox.com/asset/?id=6984519609'
local var = 1
local debounce = false
local canDoDmg = true
PunchingRemote.OnServerEvent:connect(function(plr)
local connectionRight, connectionLeft
local track1 = plr.Character.Humanoid:LoadAnimation(anim1)
local track2 = plr.Character.Humanoid:LoadAnimation(anim2)
local character = plr.Character
local humanoid = character:WaitForChild('Humanoid')
if var == 1 and debounce == false then
debounce = true
plr.leaderstats.Effort.Value = plr.leaderstats.Effort.Value + plr.Stats.Earnings.Value
track1:Play()
var = var + 1
wait(1)
debounce = false
elseif var == 2 and debounce == false then
debounce = true
plr.leaderstats.Effort.Value = plr.leaderstats.Effort.Value + plr.Stats.Earnings.Value
track2:Play()
var = 1
wait(1)
debounce = false
end
connectionRight = plr.Character.RightHand.Touched:connect(function(hit)
if hit.Parent.Humanoid and canDoDmg then
hit.Parent.Humanoid:TakeDamage(plr.Stats.Damage.Value)
canDoDmg = false
wait(1)
canDoDmg = true
end
connectionRight:Disconnect()
end)
connectionLeft = plr.Character.LeftHand.Touched:connect(function(hit)
if hit.Parent.Humanoid and canDoDmg then
hit.Parent.Humanoid:TakeDamage(plr.Stats.Damage.Value)
canDoDmg = false
wait(1)
canDoDmg = true
end
connectionLeft:Disconnect()
end)
end)
while wait(4) do
if var == 2 then
var = 1
end
end
Please help, idk what to do, i`ll mark answer.

2 comments
Thank you so much, i was thinking this was the problem but i wanted to know for sure :D, you are the best !
no problem