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

How can i make this script reduce stamina when sprinting?

Like the title asked.

UserInputService.InputBegan:connect(function(input, event)
	if event then return end
	if event then return end
	if input.KeyCode == Enum.KeyCode.W then
		if not start then
			start = tick()
		else
			if tick() - start < 0.2 then
				start = false
				if Running == false then
					print("Running")
					Running = true
					
					game.ReplicatedStorage.RemoteEvents.StartRunEvent:FireServer()
					current:Play()
					
					local RandomNumber = math.random(0, 1)
					if RandomNumber == 1 then
						Player.Data.AgilityEXP.Value = Player.Data.AgilityEXP.Value+math.random(5, 8)
						
					Player.Backpack.PlayerSetup.CombatSystem.Disabled = true
					
					end
				end
			else
				
				start = tick() --reset counter
			end
		end
	end		
end)

UserInputService.InputEnded:connect(function(input, event)
	if input.KeyCode ~= Enum.KeyCode.W then return end;
	if Running == true then
		print("Walking")
		Running = false
		game.ReplicatedStorage.RemoteEvents.StopRunEvent:FireServer()
		current:Stop()
		Player.Backpack.PlayerSetup.CombatSystem.Disabled = false
	end
end)

Is there also a way i can make it where a stamina bar goes down when the player is sprinting with this script?

1 comment

0

nvm.

1 answer

✓ Accepted answer

You have to create a variable that is not in the script like a string value and just change is number with simple math.And then you will have your stamine value.

For a basic UI bar make a script that is changing the size of the bar depending on the value of the stamina Variable that you created.

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