How do I make a pushup script begin laying at one key and do a pushup at another

I have made a push-up script that playing when you press J, however, it does it instantly without getting into the pushup position first (so you could do pushups from there), like a plank type of position.

My goal is to make it a two-step type of pushup system where you first where you first have to get into the position and then do the pushups

Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local PushUpsEvent = ReplicatedStorage:WaitForChild("PushUps")

local DoPushUpsEvent = ReplicatedStorage:WaitForChild("DoPushUps")

local Mouse = game.Players.LocalPlayer:GetMouse()

local Debounce = false

Mouse.KeyDown:Connect(function(KeyCode)
	if KeyCode == "j" then
	
	 if Debounce == false then
			
			Debounce = true
			
			print("Beginning Pushups")
			
			PushUpsEvent:FireServer()
			
			wait(1.5)
			
			Debounce = false
		end
		
		if KeyCode == "k" then
			
			if Debounce == false then

				Debounce = true

				print("Doing Pushups")

				DoPushUpsEvent:FireServer()

				wait(1.5)

				Debounce = false
			end
		end
		
	else if Debounce then return
			
		end
	end
end)

ServerScriptStorage:

-- Services

local PushUpsEvent = ReplicatedStorage:WaitForChild("PushUps")

-- Variables

local function PushUps(Player, KeyCode)
   
   local StrengthValue = Player.Stats.Strength
   
   local PlayerCharacter = game.Workspace:WaitForChild(Player.Name)
   local PlayerHumanoid = Player.Character:WaitForChild("Humanoid")
   
   local PushUpAnimationDefault = Instance.new("Animation")
   PushUpAnimationDefault.AnimationId = "rbxassetid://10903310888"
   local PushUpAnimationDefaultPlay = PlayerHumanoid:LoadAnimation(PushUpAnimationDefault, PlayerCharacter.Head)
   
   local PushUpsAnimation = Instance.new("Animation")
   PushUpsAnimation.AnimationId = "rbxassetid://10903098198"
   
   local PushUpsAnimationPlay = PlayerHumanoid:LoadAnimation(PushUpsAnimation, PlayerCharacter.Head)
   	PlayerHumanoid.WalkSpeed = 0
   	PushUpAnimationDefaultPlay:Stop()
   	PushUpsAnimationPlay:Play()
   	StrengthValue.Value = StrengthValue.Value + 1
   	wait(1)
   	PushUpsAnimationPlay:Stop()
   	PlayerHumanoid.WalkSpeed = 16
   
   if KeyCode == "j" then
   	return
   end
end

PushUpsEvent.OnServerEvent:Connect(PushUps)`
3 Likes

I recommend inserting LoadAnimation into local script and adding debounce to the ServerScriptStorage script add a variable like


local UptoTheWorkout = false -- that way you can see if player is ready to do pushups or begin to do so instead
2 Likes

I have tried to do so, it didn’t work though.

1 Like

And why not use UserInputService it’s much easier and doesn’t require alot of knowladge

1 Like

this line is useless as it will return nil and not do anything else (It doesn’t work the way you think it is) and that’s the problem too since you just end the function by pressing “J”

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.