Recently, I’ve made a sword tool, and I added a blocking system into the sword. And I scripted the sword blocking animation into a certain keybind so that the animation plays whenever a desired key is pressed. But now, for some reason you’re still able to play the blocking animation when the tool isn’t equipped. I tried looking for other solutions on the dev forum, but still haven’t found a answer yet.
It’s a local script by the way.
script:
-- wait(2)
local UIS = game:GetService("UserInputService")
local char = game.Players.LocalPlayer.Character
local hum = char:FindFirstChild("Humanoid")
local walkspeed = hum.WalkSpeed
local blockSpeed = hum.WalkSpeed / 2
local block = game:GetService("ReplicatedStorage").Block
UIS.InputBegan:Connect(function(input,inchat)
if inchat then
elseif input.KeyCode == Enum.KeyCode.F then
hum.WalkSpeed = blockSpeed
local Anim = script.Block
playanim = hum:LoadAnimation(Anim)
playanim:Play()
block:FireServer()
end
end)
UIS.InputEnded:Connect(function(input,inchat)
if inchat then
elseif input.KeyCode == Enum.KeyCode.F then
hum.WalkSpeed = walkspeed
playanim:Stop()
block:FireServer()
end
end)
hum.block.Changed:Connect(function()
if hum.block.Value == false then
playanim:Stop()
end
end)