Animation not stopping

I’m trying to make a block for my game, but the animation for the block isn’t stopping.

LocalScript:

local block = game.ReplicatedStorage.Block
local UIS = game:GetService("UserInputService")
local blockanim
local plr = game.Players.LocalPlayer
local char = script.Parent
local blocking = false

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.F then
		local tool = char:FindFirstChildWhichIsA("Tool")
		if tool.ItemClass.Value == "Weapon" then
			if blocking == false then
				local blockanim = tool:FindFirstChild("Block")
				block:FireServer(blocking, tool)
				blocking = true
				wait(1)
				block:FireServer(blocking, tool)
				blocking = false
			end
		end
	end
end)

ServerScript:

local block = game.ReplicatedStorage.Block
local blockanim

block.OnServerEvent:Connect(function(plr, blocking, tool)
	local char = plr.Character
	local hum = char.Humanoid
	blockanim = hum:LoadAnimation(tool.Block)
	if blocking == false then
		local ff = Instance.new("ForceField", char)
		ff.Name = "BlockFF"
		blockanim:Play()
	else
		char:FindFirstChild("BlockFF"):Destroy()
		blockanim:Stop()
	end
end)

If anyone knows what’s wrong please tell me.

1 Like
local block = game.ReplicatedStorage.Block
local UIS = game:GetService("UserInputService")
local blockanim
local plr = game.Players.LocalPlayer
local char = script.Parent
local blocking = false

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.F then
		local tool = char:FindFirstChildWhichIsA("Tool")
		if tool.ItemClass.Value == "Weapon" then
			if blocking == false then
				local blockanim = tool:FindFirstChild("Block")
                             blocking = true
				block:FireServer(blocking, tool)
				
				wait(1)
                blocking = false
				block:FireServer(blocking, tool)
				
			end
		end
	end
end)

ServerScript:

local block = game.ReplicatedStorage.Block
local blockanim

block.OnServerEvent:Connect(function(plr, blocking, tool)
	local char = plr.Character
	local hum = char.Humanoid
	blockanim = hum:LoadAnimation(tool.Block)
	if blocking == true then
		local ff = Instance.new("ForceField", char)
		ff.Name = "BlockFF"
		blockanim:Play()
	else
		if char:FindFirstChild("BlockFF") then
char:FindFirstChild("BlockFF"):Destroy()
		blockanim:Stop()
	end
end)

I don’t mean any offense but all you did was add an if statement, which doesn’t fix the problem.

local block = game.ReplicatedStorage.Block
local UIS = game:GetService("UserInputService")
local blockanim
local plr = game.Players.LocalPlayer
local char = script.Parent
local blocking = false

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.F then
		local tool = char:FindFirstChildWhichIsA("Tool")
		if tool.ItemClass.Value == "Weapon" then
			if blocking == false then
				local blockanim = tool:FindFirstChild("Block")
                             blocking = true
				block:FireServer(plr,blocking, tool)
				
				wait(1)
                blocking = false
				block:FireServer(plr,blocking, tool)
				
			end
		end
	end
end)

That doesn’t do anything, plus I just moved the animation part to the local script which fixed it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.