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

Why does it randomly stop allowing you to punch?

Asked by 5 years ago

Hello, I have been making a punch script (For a fighting game) and so far it has went pretty well, but there's one problem, and that is that if you punch an enemy, sometimes it takes multiple hits, the player will be unable to punch, there are no error messages, and all I know is that it wont turn Hitting.Value to false. Everything else works fine. The layout for items you need is listed here:

LocalScript (Inside of Starter Player Scripts, Parents a animation)

01local UserInputService = game:GetService("UserInputService")
02 
03local function onInputEnded(inputObject, gameProcessedEvent)
04    -- First check if the 'gameProcessedEvent' is true
05    -- This indicates that another script had already processed the input, so this one can be ignored
06    if gameProcessedEvent then return end
07    -- Next, check that the input was a keyboard event
08    if inputObject.UserInputType == Enum.UserInputType.Keyboard then
09        print("A key was released: " .. inputObject.KeyCode.Name)
10        if inputObject.KeyCode.Name == script.Parent.Parent.Backpack.Keys.PunchKey.Value then
11 
12            if script.Parent.Parent.Backpack.UsingAbility.Value == false and script.Parent.Parent.Backpack.Hitting.Value == false then
13                    if game.Players.LocalPlayer.Backpack.Mana.Value > 10 then
14 
15                        print("ability")
View all 35 lines...

Script (Inside of Server Script Service)

01function ability(user, move)
02 
03 
04 
05    if move == "Punch" then
06        user.Backpack.Mana.Value =  user.Backpack.Mana.Value - 10
07        print(move.."was used by"..user.Name)
08        local char = user.Character
09 
10 
11        user.Backpack.UsingAbility.Value = true
12        char.RightHand.Touched:Connect(function(hit)
13            if user.Backpack.Hitting.Value == false then
14        print("slap")
15 
View all 46 lines...

There is a RemoteEvent named special in Replicated Storage In Starter Pack there are these Values: -Mana (Int) -UsingAbility (Bool) -Hitting (Bool) I also used a cel shader, which is why it has to detect for "Shader" I am a beginner at scripting, so it might be messy, sorry!

Answer this question