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

My push up training script isn't working (for loop, math.random, KeyDown)?

Asked by
mxpvjn 75
7 years ago

I've been trying to make this work for a long time now but it just does. (Does a push up once and the letters don't change)

for i = 1, 15,1 do
                Animation = script.Parent.Parent.Parent.PushUps
                AnimationTrack = plr.Character.Humanoid:LoadAnimation(Animation)
                AnimationTrack:Play()
                print("Playing")

                            number = 0

    number = math.randomseed(1,4)

    if number == 1 then
        key = "x"
        plr.PlayerGui.FistMaster.PushUps.TextLabel.Text = "X"
    end
    if number == 2 then
        key = "y"
        plr.PlayerGui.FistMaster.PushUps.TextLabel.Text = "Y"
    end
    if number == 3 then
        key = "k"
        plr.PlayerGui.FistMaster.PushUps.TextLabel.Text = "K"
    end
    if number == 4 then
        key = "t"
        plr.PlayerGui.FistMaster.PushUps.TextLabel.Text = "T"
    end
    wait(1)
        plr:GetMouse().KeyDown:connect(function(k)
        if k == key and pushUpsEnabled == true then
            presses = presses + 1
            print(presses)
        else

            presses = 0
        end
    end)
    end
1
Don't use KeyDown, tab your code correctly, and please explain more. Do you get any errors? What lines do you think the problem might be? User#11440 120 — 7y

1 answer

Log in to vote
-1
Answered by
AZDev 590 Moderation Voter
7 years ago

You can't give us code and magically expect us to know what is going on. You need to explain in detail what is happening and where you think the problem begins.

I don't have an answer to your question but I would like to show you how easy it is to use UserInputService.

local UserInputService = game:GetService("UserInputService") -- Get the UserInputService

UserInputService.InputBegan:connect(function(InputObject) -- On input from player call a function with the param InputObject. InputObject is the key the player is pressing.
    if InputObject.KeyCode == Enum.KeyCode.X then -- if the key that the user pressed was X
        print(InputObject.KeyCode) -- Print the KeyCode of the key pressed.
    end     
end)
Ad

Answer this question