every time i press e the damage seems to stack and it seems that even if i don't press e after pressing e just when my right hand touches a humanoid gets damaged it
Heres the local script
local userinputservice = game:GetService("UserInputService")
local Plr = game.Players.LocalPlayer
local char = Plr.Character or Plr.CharacterAdded:Wait()
local Humanoid = char:WaitForChild('Humanoid')
local Hit = script:WaitForChild("Hit")-- a bool value
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild('CombatFolder'):WaitForChild('RemoteEvent')
local Punch = game.ReplicatedStorage:WaitForChild('CombatFolder'):WaitForChild('Punch') -- Punch is a animation
local Debounce = true
local CoolDown = 2
local Key = 'E'
userinputservice.InputBegan:Connect(function(input,IsTyping)
if IsTyping then return end
if input.KeyCode == Enum.KeyCode[Key] and Debounce and char then
Debounce = false
local Load = Humanoid:LoadAnimation(Punch)
Load:Play()
if Load.IsPlaying and not Hit.Value then
RemoteEvent:FireServer()
end
wait(CoolDown)
Debounce = true
end
end)
and heres the server script
local Combat = game:GetService("ReplicatedStorage").CombatFolder:WaitForChild('RemoteEvent')
Combat.OnServerEvent:Connect(function(player)
local char = player.Character
if not player.Backpack.KeyBind.Hit.Value then
player.Backpack.KeyBind.Hit.Value = true
local Bool = true
char.RightHand.Touched:Connect(function(h)
if Bool == true and h.Parent.Name ~= player.Name and h.Parent:FindFirstChild('Humanoid') then
Bool = false
local EnemyHumnoid = h.Parent.Humanoid
EnemyHumnoid:TakeDamage(10)
wait(1)
Bool = true
end
end)
wait()
player.Backpack.KeyBind.Hit.Value = false
end
end)

1 comment
because characters are made of multiple body parts