I wanted to make a janky sword thing with blocking and stuff to practice,but for some reason the block works only in one way and i cannot unblock,i’m really dumb to explain it,so here’s a video
No errors are popping out as you can see (i think)
A script inside the tool:
local Tool = script.Parent
local Handle = Tool.Handle
local debounce = false
local hitdebounce = false
local BlockDebounce = false
local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SwordHit1 = Handle.SwordHit1
local SwordHit2 = Handle.SwordHit2
local BlockA = Handle.Block
local BlockLoop = Handle.BlockLoop
local hit = 1
local timeLimit = 0
--// Parameters
local cooldown = 2
--// Parameters
Tool.Equipped:Connect(function()
local Motor6d = Instance.new("Motor6D")
Motor6d.Part1 = Handle
Motor6d.Part0 = Tool.Parent["Right Arm"]
Motor6d.Parent = Handle
Motor6d.Name = "Motor6d"
print("Equipped and loaded")
local Humanoid = Tool.Parent:FindFirstChild("Humanoid")
local BlockLoaded = Humanoid:LoadAnimation(BlockA)
local SwordHit1Load = Humanoid:LoadAnimation(SwordHit1)
local SwordHit2Load = Humanoid:LoadAnimation(SwordHit2)
local BlockLoopLoad = Humanoid:LoadAnimation(BlockLoop)
-- Block function
local function Block(plr)
local HoldingPlr = game.Players:GetPlayerFromCharacter(Tool.Parent)
local IsBlock = HoldingPlr:WaitForChild("IsBlocking")
if SwordHit2Load.IsPlaying ~= true or SwordHit1Load.IsPlaying ~= true and IsBlock.Value ~= true and BlockDebounce ~= true then
BlockDebounce = true
IsBlock.Value = true
HoldingPlr.Character:FindFirstChild("Humanoid").WalkSpeed = 0
BlockLoaded:Play()
BlockLoaded.Stopped:Wait()
BlockLoopLoad:Play()
print(plr.Name .. " Is Blocking!")
task.wait(0.1)
BlockDebounce = false
elseif debounce ~= true and IsBlock.Value == true and SwordHit2Load.IsPlaying ~= true or SwordHit1Load.IsPlaying ~= true and BlockDebounce ~= true then
BlockDebounce = true
IsBlock.Value = false
HoldingPlr.Character:FindFirstChild("Humanoid").WalkSpeed = 16
BlockLoopLoad:Stop()
print(plr.Name .. " Is Not Blocking!")
task.wait(0.1)
BlockDebounce = false
elseif debounce == true or BlockDebounce == true and SwordHit2Load.IsPlaying == true or SwordHit1Load.IsPlaying == true then
end
end
-- Block function
BlockEvent = ReplicatedStorage.Block.OnServerEvent:Connect(function(player)
repeat
task.wait()
timeLimit += 1
until player.Character:FindFirstChild(Tool.Name) or timeLimit == 10
if timeLimit == 10 then
elseif timeLimit < 10 and player.Character:FindFirstChild(Tool.Name) then
Block(player)
end
end)
end)
Tool.Activated:Connect(function()
local Humanoid = Tool.Parent:FindFirstChild("Humanoid")
local SwordHit1Load = Humanoid:LoadAnimation(SwordHit1)
local SwordHit2Load = Humanoid:LoadAnimation(SwordHit2)
if debounce ~= true then
print("Debounce is false")
debounce = true
if hit == 1 then
hit += 1
SwordHit1Load:Play()
local TouchEvent = Handle.Touched:Connect(function(hit)
if hit then
if hit.Parent:FindFirstChild("Humanoid") and Humanoid.Parent.Name ~= hit.Parent.Name then
local EnemyHumanoid = hit.Parent:FindFirstChild("Humanoid")
if game.Players:GetPlayerFromCharacter(hit.Parent) then -- If enemy is player
if game.Players:GetPlayerFromCharacter(hit.Parent):FindFirstChild("IsBlocking").Value ~= true then
-- if not blocking
if hitdebounce == false then
EnemyHumanoid:TakeDamage(10)
hitdebounce = true
else
end
else
-- if blocking
end
else
-- if enemy is an npc
EnemyHumanoid:TakeDamage(10)
end
end
end
end)
SwordHit1Load.Stopped:Wait()
TouchEvent:Disconnect()
task.wait(cooldown)
debounce = false
hitdebounce = false
elseif hit == 2 then
hit -= 1
SwordHit2Load:Play()
local TouchEvent = Handle.Touched:Connect(function(hit)
if hit then
if hit.Parent:FindFirstChild("Humanoid") and Humanoid.Parent.Name ~= hit.Parent.Name then
local EnemyHumanoid = hit.Parent:FindFirstChild("Humanoid")
if game.Players:GetPlayerFromCharacter(hit.Parent) then -- If enemy is player
if game.Players:GetPlayerFromCharacter(hit.Parent):FindFirstChild("IsBlocking").Value ~= true then
-- if not blocking
if hitdebounce == false then
EnemyHumanoid:TakeDamage(10)
hitdebounce = true
else
end
else
-- if blocking
end
else
-- if enemy is an npc
EnemyHumanoid:TakeDamage(10)
end
end
end
end)
SwordHit2Load.Stopped:Wait()
TouchEvent:Disconnect()
task.wait(cooldown)
debounce = false
hitdebounce = false
end
else
end
end)
Tool.Unequipped:Connect(function()
BlockEvent:Disconnect()
end)
A local script inside StarterPlayerScripts that sends the block remote event
local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function SendBlock()
ReplicatedStorage:WaitForChild("Block"):FireServer()
end
ContextActionService:BindAction("Block",SendBlock,false,Enum.KeyCode.F)
and the insides of the sword tool
How can i make the block go 2 ways? (i mean so i could unblock)
Thanks in adance.