Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Punching Damage doesn't work right????

Asked by 7 years ago
Edited 7 years ago
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local Combo = 1
local enabled = true
local CanDamage = false

mouse.KeyDown:connect(function(key)
if key == "q" then
        if Combo == 1 then
if not enabled then return end
enabled = false
            local a = player.Character.Humanoid:LoadAnimation(script.Punch1):Play()
wait(0.5)
            Combo = 2
enabled = true
mouse.KeyDown:connect(function(key)
if key == "q" then
                if Combo == 2 then
    if not enabled then return end
enabled = false
                       local b = player.Character.Humanoid:LoadAnimation(script.Punch2):Play()
        wait(0.5)
        Combo = 3
enabled = true
mouse.KeyDown:connect(function(key)
if key == "q" then
                if Combo == 3 then
    if not enabled then return end
enabled = false
                       local c = player.Character.Humanoid:LoadAnimation(script.Kick):Play()
        wait(0.5)
        Combo = 1
enabled = true
end

game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name)['LeftHand'].Touched:connect(function(part)
    local human= part.Parent:findFirstChild("Humanoid")
    if human then
        if human.Parent.Name~= game.Players.LocalPlayer.Name and CanDamage == false then
    CanDamage = true
            human:TakeDamage(10)
            wait(1.2)
            CanDamage = false
        end
    end
end)
game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name)['RightHand'].Touched:connect(function(part)
    local human= part.Parent:findFirstChild("Humanoid")
    if human then
        if human.Parent.Name~= game.Players.LocalPlayer.Name and CanDamage == false then
        CanDamage = true
            human:TakeDamage(10)
            wait(1.2)
            CanDamage=false
        end
    end
end)
end
end)
end
end
end)
end
end
end)

Basically I tried to change the CanDamage Variable to false instead of true i switched places between them and nothing seems to work It does damage even when the animation is not playing.

Help me please.

0
Why did you do so many separate events? (mouse.KeyDown) RevergeHelps 63 — 7y
0
You can use and statements like if debounce1 == false and debounce2 == false then hiimgoodpack 2009 — 7y

1 answer

Log in to vote
0
Answered by
Neu_Dev 22
7 years ago

First of all using Mouse to use keyboard is limited use and also deprecated its a bad practice to use it, i suggest start using "UserIputService" which you will have more control on your input.

API http://wiki.roblox.com/index.php?title=API:Class/UserInputService

How to use one http://wiki.roblox.com/index.php?title=API:Class/UserInputService/InputBegan

Example:

This example must be inside of your player or character and must be localscript or else wont work.

this will work also inside of the tool because since tool is equipped then tool is transferred to the player character since localscript is inside the tool. got it?

---LOCALSCRIPT

local player = game.Players.LocalPlayer -- This will only work on local script, on normal script it is not
local UIS = game:GetSerivce("UserInputService")
local Anim = player.Character.Humanoid:LoadAnimation(script.Punch1)
local Anim2 = player.Character.Humanoid:LoadAnimation(script.Punch2)
Combo = 1
CanDamage = false


UIS.InputBegan:connect(function(key, gameproc)
    if not gameproc and key.KeyCode == Enum.KeyCode.Q and Combo == 1 then
        CanDamage = true
        Combo = 2
        Anim:Play()
        local lefthand = player.Character:FindFirstChild("LeftHand")
        lefthand.Touched:connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and CanDamage == true then
            hit.Parent:FindFirstChild("Humanoid"):TakeDamage(10)
        end
        wait(0.1)
        CanDamage = false
    elseif not gameproc and key.KeyCode == Enum.KeyCode.Q and Combo == 2 then
        CanDamage = true
        Combo = 3
        Anim2:Play()
        local lefthand = player.Character:FindFirstChild("LeftHand")
        lefthand.Touched:connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and CanDamage == true then
            hit.Parent:FindFirstChild("Humanoid"):TakeDamage(10)
        end
        wait(0.1)
        CanDamage = false
    ---- and Continue it
    end
end)

Gameproc or GameProcessed needs to be check false so while in the middle of typing in chat the input or key you set is pressed wont activate it. so it will not be annoying sometimes.

Press answer if this helps you! ~~Neuroticxs

0
also just add a if statement when the tool is equipped or not so it wont punch randomly if the tool is unequipped Neu_Dev 22 — 7y
0
I am getting an error on the elseif not line . when I fix this , it's saying Error getting Service from DataModel anyway it doesn't get service for the UIS this is why I don't use it . DarkWQlfc 20 — 7y
0
What do you mean? It perfectly works for me? You did something wrong Neu_Dev 22 — 7y
0
Also you might have to at a repeat wait() until game.Players.LocalPlayer.Character so it wont automatically runs the script while player is still loading and that might have broke the script Neu_Dev 22 — 7y
0
Nvm I figured it out DarkWQlfc 20 — 7y
Ad

Answer this question