so I have made the animation work just fine but I cant seem to get the script working so that if a player is blocking and they were hit they take less damage.
here is my animation script:
local UIS = game:GetService('UserInputService')
local BlockAnim = script:WaitForChild('BlockAnim')
local KeyDown = false
local Hum = game.Players.LocalPlayer.Character.Humanoid
local anim = Hum:LoadAnimation(BlockAnim)
local tool = game.StarterPack.ClassicSword
local char = game.Players.LocalPlayer.Character
local isBlocking = tool.Handle.IsBlocking.Value
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
KeyDown = true
end
while KeyDown == true do
isBlocking = true
print(isBlocking)
game.StarterPlayer.CharacterWalkSpeed = 0
game.StarterPlayer.CharacterJumpPower = 25
anim:Play()
wait(.01)
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
KeyDown = false
end
while KeyDown == false do
isBlocking = false
print(isBlocking)
game.StarterPlayer.CharacterWalkSpeed = 16
game.StarterPlayer.CharacterJumpPower = 50
anim:Stop()
wait(.1)
end
end)
I made a variable for if the player is blocking (isBlocking) this might help you. idk i also have no idea on where to start.
Sword Script:
local cooldown = script.Parent.Parent.CoolDown.Value
local tool = script.Parent.Parent
local isblocking = tool.Handle.IsBlocking.Value
script.Parent.Touched:Connect(function(hit)
script.Parent.Parent.Activated:Connect(function()
local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid and cooldown == false then
Humanoid:TakeDamage(7)
cooldown = true
wait(.5)
cooldown = false
end
end)
end)

1 comment
Im not that good at coding so could u please show a example code of it?