Hello,
I created a punch script today and it was running fine until I implemented the damage.
When I punch away from the Dummy, and walk into it, it damages the player.
Thank you
Video showcasing the problem:
Local Code(Focus on the DealDamage event):
local Combo = 0
local LastTick = tick()
local Debounce = false
local ComboDebounce = false
local UserInputService = game:GetService('UserInputService')
function DealDamage(Part,Number)
local HasTouched = Part.Touched:Wait(0.4)
if HasTouched then
if HasTouched.Parent:FindFirstChild('Humanoid') then
print('So good')
if Combo == 3 then
game.ReplicatedStorage.GameRemotes.DamageEvent:FireServer(HasTouched.Parent,Number,true,true)
else
game.ReplicatedStorage.GameRemotes.DamageEvent:FireServer(HasTouched.Parent,Number,true,false)
end
end
else
end
end
function Attack(InputObject)
if InputObject.UserInputType == Enum.UserInputType.MouseButton1 and ComboDebounce == false and Debounce == false then
Debounce = true
print(math.abs(math.floor(LastTick - tick())))
if math.abs(math.floor(LastTick - tick())) > 3 then
Combo = 0
print('WEAPON | Combo reset as it had been left for 2')
end
Combo = Combo + 1
if Combo == 1 then
script.Parent.Events.PlayAnimation:FireServer(script.Parent.Objects['1'])
DealDamage(game.Players.LocalPlayer.Character.RightHand,10)
else if Combo == 2 then
print('2')
script.Parent.Events.PlayAnimation:FireServer(script.Parent.Objects['2'])
DealDamage(game.Players.LocalPlayer.Character.LeftHand,10)
else
print('3')
script.Parent.Events.PlayAnimation:FireServer(script.Parent.Objects['3'])
DealDamage(game.Players.LocalPlayer.Character.HumanoidRootPart,20)
ComboDebounce = true
wait(1)
ComboDebounce = false
Combo = 0
end
end
LastTick = tick()
wait(0.4)
Debounce = false
end
end
UserInputService.InputBegan:Connect(Attack)