#Blocking in combat {SOLVED}

51 messages · Page 1 of 1 (latest)

storm girder
#

Hey,
Its me again...
Now Im trying to add block feature to my game. I dont know wheres issue tbh.. Can someone help?

local UIS = game:GetService("UserInputService")
local char = game.Players.LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")
local Animation = hum:LoadAnimation(script:WaitForChild("block"))
local BlockSystem = char:WaitForChild("BlockSystem")

local speed = 16
local blockspeed = 8

UIS.InputBegan:Connect(function(input)
   if input.KeyCode == Enum.KeyCode.F then
       Animation:Play()
       hum.Walkspeed = blockspeed
       BlockSystem.Value = true
   end
end)

UIS.InputEnded:Connect(function(input)
   if input.KeyCode == Enum.KeyCode.F then
       Animation:Stop()
       hum.Walkspeed = speed
       BlockSystem.Value = false
   end
end)

I know it isnt fully done, but Value and Walkspeed does not work so I cant continue.

white vortex
#

to UserInputService you must also use two more line of codes for InputBegan and InputEnded

One is about gameProcessed which I'm not sure about, but I think it means if the player isn't chatting
Second is about the style which will be, looking at these keybinds, Keyboard so the final code should be:

local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() -- This makes sure that the character actually exists
local hum = char:WaitForChild("Humanoid")
local Animation = hum:LoadAnimation(script:WaitForChild("block"))
local BlockSystem = char:WaitForChild("BlockSystem")

local speed = 16
local blockspeed = 8

UIS.InputBegan:Connect(function(input, gameProcessed)
  if not gameProcessed then
      if input.UserInputType == Enum.UserInputType.Keyboard then
          if input.KeyCode == Enum.KeyCode.F then
               Animation:Play()
               hum.WalkSpeed = blockspeed
               BlockSystem.Value = true
            end
        end
    end
end)

UIS.InputEnded:Connect(function(input, gameProcessed)
  if not gameProcessed then
      if input.UserInputType == Enum.UserInputType.Keyboard then
          if input.KeyCode == Enum.KeyCode.F then
               Animation:Stop()
               hum.WalkSpeed = speed
               BlockSystem.Value = false
            end
        end
    end
end)
#

If there are any errors please tag me here

#

sorry you also have one more mistake @storm girder

quiet juniperBOT
#

studio** You are now Level 7! **studio

white vortex
#

it doesn't seem that big, but in programming it does a big difference

#

you have hum.Walkspeed, but roblox named it WalkSpeed

#

so the lowercase s might also be the thing erroring

#

and while we're at it you might aswell do this change at the second line for the char

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() -- This makes sure that the character actually exists
storm girder
#

Sorry for late respond I was in gym

#

Tysm for all of those advices and codes😅. U are life saver!

#

Also I guess I gonna have problem with connecting it to punch script

quiet juniperBOT
#

studio** You are now Level 4! **studio

storm girder
#

Can u help me with that also please? I gonna send script when I get home

storm girder
#

okay blocking is working, tyam

#

tysm

#

Here is my punch script

local cas = game:GetService("ContextActionService")
local rs = game:GetService("ReplicatedStorage")

local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")

local StunHandler = require(game.StarterPlayer.StarterPlayerScripts.StunHandler)
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()

local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")


local leftPunch = animator:LoadAnimation(script:WaitForChild("LeftPunch"))
local rightPunch = animator:LoadAnimation(script:WaitForChild("RightPunch"))
local headPunch = animator:LoadAnimation(script:WaitForChild("HeadPunch")) 

local currentPunch = 0
local lastPunch = 0

local debounce = false

local function punch()
    if debounce then return end
    if tick() - lastPunch > 1.5 then
        currentPunch = 0
    end

    debounce = true
    if currentPunch == 0 then
        rightPunch:Play()
        task.wait(0.3)
        hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3, 0)
        task.wait(0.1)
        
    elseif currentPunch == 1 then
        leftPunch:Play()
        task.wait(0.3)
        hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3, 0)
        task.wait(0.1)
        
    elseif currentPunch == 2 then
        headPunch:Play()
        task.wait(0.3)
        hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 15, 0.3, 140) 
        task.wait(3)
    end
    

    debounce = false

    if currentPunch == 2 then
        currentPunch = 0
    else
        currentPunch = currentPunch + 1
    end

    lastPunch = tick()
end

cas:BindAction("Punch", punch, true, Enum.UserInputType.MouseButton1)
#

Also as u can see I have
"local StunHandler = require(game.StarterPlayer.StarterPlayerScripts.StunHandler)"
(if yk that module called StunHandlerV2)
And I have some issues with connecting that stun after 3rd punch (headpunch), It just stun me :D.
Could u help me please? @white vortex

storm girder
#

forget about those stuns, Its pretty complicated

white vortex
#

Once i get home I'll look at it at least

storm girder
#

wait, I did something, but i didnt tested it yet, cuz dummy cant apply DefenceSystem

local cas = game:GetService("ContextActionService")
local rs = game:GetService("ReplicatedStorage")

local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")

local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()

local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local BlockSystem = character:WaitForChild("BlockSystem")

local leftPunch = animator:LoadAnimation(script:WaitForChild("LeftPunch"))
local rightPunch = animator:LoadAnimation(script:WaitForChild("RightPunch"))
local headPunch = animator:LoadAnimation(script:WaitForChild("HeadPunch")) 

local currentPunch = 0
local lastPunch = 0
local damage = 10
local last = damage + 5


local debounce = false

local function punch()
    if debounce then return end
    if tick() - lastPunch > 1.5 then
        currentPunch = 0
    end
    
    if BlockSystem.Value == true then
        damage = damage /2
        last = last /2
    else
        damage = damage
        last = last
        
    end

    debounce = true
    if currentPunch == 0 then
        rightPunch:Play()
        task.wait(0.3)

        hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), damage, 0.3, 0)
        task.wait(0.1)

    elseif currentPunch == 1 then
        leftPunch:Play()
        task.wait(0.3)
        hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), damage, 0.3, 0)
        task.wait(0.1)

    elseif currentPunch == 2 then
        headPunch:Play()
        task.wait(0.3)
        hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), last, 0.3, 140) 
        task.wait(3)
    end


    debounce = false

    if currentPunch == 2 then
        currentPunch = 0
    else
        currentPunch = currentPunch + 1
    end

    lastPunch = tick()
end

cas:BindAction("Punch", punch, true, Enum.UserInputType.MouseButton1)
#

Do u think that this wil work (without stun, cuz stun is just too hard to add for me)

storm girder
white vortex
#

I think it could work

#

but there is one thing

#

it should be

#
cas:BindAction("Punch", punch, true, Enum.KeyCode.MouseButton1)
#

the last line @storm girder

#

btw thanks, this made me read more about ContextActionService because I never really used it and I wasn't sure about the "Enum.UserInputType.MouseButton1". And by reading it I found out that ContextActionService can create Touch Button :D Another thing to my coding skills that I can use ;)

storm girder
#

Oh thanks too for feedback 😅

storm girder
#

Also do u know how to make that stuns work? (StunHandlerV2) @white vortex

#

Or do u know any other stuns

white vortex
#

I never used StunHandlerV2 but I found this article from the developer of the model read more here: https://devforum.roblox.com/t/stun-handler-v21/1072859
It's really simple I would say :)

#

Also so you don't get confused which I doubt but to make sure in the line

local StunHandler = require(path.to.module)

make sure to replace the path.to.module with the path (e. g.

local StunHandler = require(game:GetService("ReplicatedStorage").ModuleName) -- Replace the "Module Name" with the Module Name
#

@storm girder

storm girder
#

I did it

#

But it stun me

#

Not that npc

#

So I guess theres some issue with me lol

#

@white vortex

white vortex
#

no, but you to test it I think you can create a Bool Value inside the NPC

#

or wait

#

I'ma try it

storm girder
#

Okay

#

Tysm

white vortex
#

I can't really help with stunts as I never used it and don't understand it that much, sorry :)

storm girder
#

But it dont change a fact, that Im Getting stunned

storm girder
white vortex
#

no problem, if I get it to work I'll text you

storm girder
#

Okay, tysm!