Everything works in this script but when I reset the animation stops working and also the other player does not take any damage anymore.
In the output it still prints "Player pressed down the F key", and I don't get any errors what I can see. Is there anything that I have to change to be able to fix this problem?
--local script
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punch = ReplicatedStorage:WaitForChild("Punch")
local damaged = false
local PunchValue = false
local db = true
local leftPunch = script.LeftPunch
local rightPunch = script.RightPunch
wait(0.1)
local player = game.Players.LocalPlayer
local char = player.character
local hum = char.Humanoid
local leftHand = char.LeftHand
local rightHand = char.RightHand
local leftPunchTrack = hum:LoadAnimation(leftPunch)
local rightPunchTrack = hum:LoadAnimation(rightPunch)
leftHand.Touched:connect(function(hit)
print(hit)
if hit.Parent:FindFirstChild("Humanoid") and not db and not damaged and hit.Parent.Humanoid~= game.Players.LocalPlayer.Character.Humanoid then
if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
damaged = true
punch:FireServer(hit.Parent.Humanoid)
end
end
end)
rightHand.Touched:connect(function(hit)
print(hit)
if hit.Parent:FindFirstChild("Humanoid") and not db and not damaged and hit.Parent.Humanoid~= game.Players.LocalPlayer.Character.Humanoid then
if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
damaged = true
punch:FireServer(hit.Parent.Humanoid)
end
end
end)
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.F and db == true then
db = false
print("Player pressed down the F key")
if PunchValue == false then
PunchValue = true
leftPunchTrack:Play()
elseif PunchValue == true then
rightPunchTrack:Play()
PunchValue = false
end
wait(1.5)
damaged = false
db = true
end
end)
--Server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punch = ReplicatedStorage:WaitForChild("Punch")
punch.OnServerEvent:Connect(function(player, humanoid)
if humanoid.Health >= 10 then
humanoid.Health = humanoid.Health -10
elseif humanoid.Health < 10 then
humanoid.Health = 0
end
end)
Thanks, Xsodar
