Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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 comment

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?

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.