So im making a fighting game and I have this script that seems to run well, but only works once. Also, the output doesn't show any error so I don't know what is wrong.
This script below is in StarterCharacterScripts
--// Services
local UserInputService = game:GetService('UserInputService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')
--// Debounces
local Punching = false
local Damaging = true
--// Customisation
local Damage = 15
local Cooldown = 0.8
--// Events
local PunchEvent = ReplicatedStorage:WaitForChild('PunchEvent')
--// Player
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Character:FindFirstChildOfClass('Humanoid')
local RightArm = Character:WaitForChild('Right Arm')
--//Animations
Punch = Instance.new('Animation')
Punch.AnimationId = 'rbxassetid://6290637671'
PunchTrack = Humanoid:LoadAnimation(Punch)
--// Coding
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E and not Punching then
Punching = true
PunchTrack:Play()
PunchTrack.KeyframeReached:Connect(function(Keyframe)
if Keyframe == 'End' then
wait(Cooldown)
Punching = false
Damaging = true
end
end)
end
end)
RightArm.Touched:Connect(function(hitPart)
if Punching and hitPart.Parent:FindFirstChild('Humanoid') and Damaging
then
Damaging = false
local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid')
PunchEvent:FireServer(HumanoidToDamage, Damage)
end
end)
