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

How do I make this happen for a certain amount of time?

repeat wait() until game.Players.LocalPlayer

m = game.Players.LocalPlayer:GetMouse()

m.KeyDown:connect(function(key)

if key == "0" then

	print("Running")

	game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 12

end

end)

m.KeyUp:connect(function(key)

if key == "0" then

	game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 5 

end

end)

Ok so ya know how in real life you can only run for a certain amount of time before you have to stop and take a breath? That's kind of what I want to happen here. I want the Player to be able to run for 10 seconds before having to stop. Then after the Player is done running and he or she waits for 4 seconds then the player can only run for 4 seconds. You get what I'm saying?

2 comments

0

Edit your question to correct the code formatting. Make your explanation decently professional, this isn't a back-alley deal -- being clear, and more importantly, acting like you care, is a great way to get people to want to help.

0

I will talk how i like and i will let u talk how you want to... not everyone understands formal writing

2 answers

✓ Accepted answer

You need to add a new variable which I guess we could call stamina. To do this, you want the bar to be depleted while running and replenished while not. This should work:

repeat wait() until game.Players.LocalPlayer
m = game.Players.LocalPlayer:GetMouse()
Stamina=10
Running=false
On=false

m.KeyDown:connect(function(key)
if key == "0" then
	print(Stamina)
	if Stamina>=1 then
		Running=true
		print("Running")
	end
	while Running==true do
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24
		wait(.1)
		Stamina=Stamina-.1
		if Stamina<=0 then
			Running=false
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
			end
		end
	end
end)

m.KeyUp:connect(function(key)
	if key == "0" then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
		if On==false then
			while Running==false and Stamina<10 do
				On=true
				wait(.1)
				Stamina=Stamina+.1
			end
			On=false
		end
	end
end)

I added a 'stamina' and'running' variable that work together to tell if the player had enough stamina or not, and if they're running or not. If you have any questions, please leave a comment :P

1 comment

0

how would i add a stamina bar? i wus gonna ask that in the question but forgot to... i have the gui and frames and everything but how would i make them work?

For a 'stamina bar' - you'll need to setup a basic gui first

Suggestion:

ScreenGui Frame -- (the background) - Size, (0,100,0,20) Bar -- another 'Frame' object, size (1,0,1,0)

-- whilst either of the stamina + / - loops are running, do this:

maxStamina = Stamina -- which is 10 here

Bar.Size = UDim2.new( Stamina/maxStamina, 0, 1, 0)

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