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
01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03 
04local Combo = 1
05local enabled = true
06local CanDamage = false
07 
08mouse.KeyDown:connect(function(key)
09if key == "q" then
10        if Combo == 1 then
11if not enabled then return end
12enabled = false
13            local a = player.Character.Humanoid:LoadAnimation(script.Punch1):Play()
14wait(0.5)
15            Combo = 2
View all 66 lines...

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

01local player = game.Players.LocalPlayer -- This will only work on local script, on normal script it is not
02local UIS = game:GetSerivce("UserInputService")
03local Anim = player.Character.Humanoid:LoadAnimation(script.Punch1)
04local Anim2 = player.Character.Humanoid:LoadAnimation(script.Punch2)
05Combo = 1
06CanDamage = false
07 
08 
09UIS.InputBegan:connect(function(key, gameproc)
10    if not gameproc and key.KeyCode == Enum.KeyCode.Q and Combo == 1 then
11        CanDamage = true
12        Combo = 2
13        Anim:Play()
14        local lefthand = player.Character:FindFirstChild("LeftHand")
15        lefthand.Touched:connect(function(hit)
View all 34 lines...

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