im making a battlegrounds game following a yt tutorial and it all works but the block, and when i start holding F the block works but when i release F it still holds the block anim heres the script
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Events = ReplicatedStorage:WaitForChild("Events")
local Character = script.Parent.Parent
local IsBlocking = false
UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
if GameProcessedEvent then
return
end
if Input.UserInputType == Enum.UserInputType.MouseButton1 and not IsBlocking then
Events.ClickAttack:FireServer()
end
if Input.KeyCode == Enum.KeyCode.F then
IsBlocking = true
Events.Block:FireServer(true)
end
end)
UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent)
if GameProcessedEvent then
return
end
if Input.KeyCode == Enum.KeyCode.F then
IsBlocking = false
Events.Block:FireServer(false)
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Events = ReplicatedStorage:WaitForChild("Events")
local AttackHitboxes = require(script.Parent:WaitForChild("AttackHitboxes"))
local ClickAttackDebounces = {}
Events.ClickAttack.OnServerEvent:Connect(function(player, mousePosition)
local character = player.Character
if not character then
return
end
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid or humanoid.Health <= 0 then
return
end
if ClickAttackDebounces[player] then
return
end
-- Your attack logic here
ClickAttackDebounces[player] = true
local PunchCombo = player.Values:FindFirstChild("PunchCombo")
if not PunchCombo then
ClickAttackDebounces[player] = nil
return
end
local Animation = script.PunchAnimationCycle:FindFirstChild(tostring(PunchCombo.Value))
if not Animation then
ClickAttackDebounces[player] = nil
return
end
local LoadedPunchAnimation = humanoid:FindFirstChild("Animator"):LoadAnimation(Animation)
LoadedPunchAnimation:Play()
if tonumber(PunchCombo.Value) >= 4 then
PunchCombo.Value = 1
else
PunchCombo.Value += 1
end
AttackHitboxes.CreateHitbox(character, Vector3.new(9, 9, 5), 10, true)
task.wait((LoadedPunchAnimation.Length + 0.1)) -- Fixed spelling of 'Length'
if ClickAttackDebounces[player] then
ClickAttackDebounces[player] = nil
end
end)
Events.Block.OnServerEvent:Connect(function(Player, Value)
local character = Player.Character
if not character then
return
end
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid or humanoid.Health <= 0 then
return
end
if ClickAttackDebounces[player] then
return
end
if not Value then
local LoadedAnimations = humanoid.Animator:GetPlayingAnimationTracks()
for _, v in LoadedAnimations do
if v.Name == "BlockAnimation" then
v:Stop()
end
end
if character:FindFirstChild("Blocking") then
character.Blocking:Destroy()
end
else
local BlockAnimation = humanoid.Animator:LoadAnimation(script.Animations.Block)
BlockAnimation:Play()
local Blocking = Instance.new("StringValue")
Blocking.Name = "Blocking"
Blocking.Parent = character
end
end)